所以我试图在我的辅助显示器上打开一个最大化的窗口。一切正常,除了它的高度比它应该的低2个像素。
我的辅助显示器的分辨率为 1280x1024。但是,一旦我检查窗口,它就是 1280x1022。有谁知道这个问题?
操作系统:Windows 10
这是一些代码:
SecondaryMonitorWindow smw = new SecondaryMonitorWindow();
smw.Show();
XAML
Loaded="OnWindowLoaded"
WindowStartupLocation="Manual"
WindowStyle="None"
SnapsToDevicePixels="True"
Height="1280"
Width="1024"
构造函数
public SecondaryMonitorWindow()
{
InitializeComponent();
Instance = this;
}
事件
private void OnWindowLoaded(object sender, RoutedEventArgs e)
{
this.MaximizeToSecondaryMonitor();
}
扩展方法
public static void MaximizeToSecondaryMonitor(this Window window)
{
var secondaryScreen = Windows.Forms.Screen.AllScreens.Where(s => !s.Primary).FirstOrDefault();
if (secondaryScreen != null)
{
if (!window.IsLoaded)
window.WindowStartupLocation = WindowStartupLocation.Manual;
window.Left = secondaryScreen.WorkingArea.Left;
window.Top = secondaryScreen.WorkingArea.Top;
window.Width = secondaryScreen.WorkingArea.Width;
window.Height = secondaryScreen.WorkingArea.Height;
if (window.IsLoaded)
window.WindowState = WindowState.Maximized;
}
}