Reputation: 639
I would like to have two startup options in my application, to start it maximized, and to start it minimized. No problem here, but I would also like them to have both checked, and in that case I would like it to start minimized, but if the user clicks the application to show it then it should be maximized (cover the whole screen). I thought that if I first maximized it befor minimizing it should stay that way, but thats not the case, here instead it just get minimized, and then when opened it's in the "normal" state.
if (ConfigHandler.Instance.Fullscreen)
this.WindowState = WindowState.Maximized;
if (ConfigHandler.Instance.Minimized)
this.WindowState = WindowState.Minimized;
Upvotes: 0
Views: 1401
Reputation: 17115
It's StateChanged event you're looking for.
public MainWindow()
{
InitializeComponent();
if (ConfigHandler.Instance.Minimized)
WindowState = System.Windows.WindowState.Minimized;
this.StateChanged += MainWindow_StateChanged;
}
void MainWindow_StateChanged(object sender, EventArgs e)
{
if (ConfigHandler.Instance.Fullscreen)
WindowState = System.Windows.WindowState.Maximized;
this.StateChanged -= MainWindow_StateChanged;//to prevent further effect
}
Upvotes: 1