WPF多屏显示及最大化
XAML去除WindowState的最大化
若未去除XAML中的WindowState设定为 Maximized 属性会导致非主屏窗口自动最大化显示到主屏窗口。 设定显示窗口显示屏幕
在构造函数中根据需要设定显示到指定屏幕位置并增加 Loaded 处理函数,在此函数中设置窗口最大化状态。 using Screen = System.Windows.Forms.Screen; void ShowOnMonitor(Window win, int monitorIndex) { int screenCount = Screen.AllScreens.Count(); if (monitorIndex >= screenCount) monitorIndex = 0; Screen sc = Screen.AllScreens[monitorIndex]; win.WindowStartupLocation = WindowStartupLocation.Manual; win.Top = sc.WorkingArea.Top; win.Left = sc.WorkingArea.Left; win.Width = sc.WorkingArea.Width; win.Height = sc.WorkingArea.Height; win.Loaded += Window_Loaded; } private void Window_Loaded(object sender, RoutedEventArgs e) { var senderWindow = sender as Window; if (null == senderWindow) return; senderWindow.WindowState = WindowState.Maximized; }