I suggest you to use Screen
class from System.Windows.Forms
to define whether your application is on the second screen. It is necessary to know when a user moves your application to the second display and to know it, I use LocationChanged
event:
Code-behind:
private Screen GetSecondaryScreen()
{
foreach (Screen screen in Screen.AllScreens)
{
if (screen != Screen.PrimaryScreen)
return screen;
}
return Screen.PrimaryScreen;
}
private void Window_LocationChanged(object sender, EventArgs e)
{
if (Screen.PrimaryScreen != GetSecondaryScreen())
{
this.WindowState = WindowState.Maximized;
}
}
XAML:
<Window x:Class="DateTimePickerDataGridWPF.MainWindow"
...the code omitted for the brevity...
Title="MainWindow" Height="350" Width="525" LocationChanged="Window_LocationChanged">
</Window>