若未去除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;}
电脑