Reputation: 217
I want to display a Window on secondary monitor, as follows:
Queue<string> itemQueue = new Queue<string>();
MonitorWindow monitor = new MonitorWindow(itemQueue);
var secondaryScreen = System.Windows.Forms.Screen.AllScreens.Where(s => !s.Primary)
.FirstOrDefault();
if (secondaryScreen != null)
{
monitor.WindowStartupLocation = WindowStartupLocation.Manual;
var workingArea = secondaryScreen.WorkingArea;
monitor.Left = workingArea.Left;
monitor.Top = workingArea.Top;
monitor.Width = workingArea.Width;
monitor.Height = workingArea.Height;
monitor.Show();
}
The properties have correct values, but this maximizes the Window on the primary monitor. can you help me?
Upvotes: 1
Views: 368
Reputation: 217
Ok, I've fixed the problem with remove the property WindowState="Maximized" in XAML code of MonitorWindow and changed the program as follows:
Queue<string> itemQueue = new Queue<string>();
MonitorWindow monitor = new MonitorWindow(itemQueue);
var secondaryScreen = System.Windows.Forms.Screen.AllScreens.Where(s => !s.Primary).FirstOrDefault();
if (secondaryScreen != null)
{
if (!monitor.IsLoaded)
monitor.WindowStartupLocation = WindowStartupLocation.Manual;
var workingArea = secondaryScreen.WorkingArea;
monitor.Left = workingArea.Left;
monitor.Top = workingArea.Top;
monitor.Width = workingArea.Width;
monitor.Height = workingArea.Height;
// If window isn't loaded then maxmizing will result in the window displaying on the primary monitor
monitor.Show();
if (monitor.IsLoaded)
monitor.WindowState = WindowState.Maximized;
}
Upvotes: 2