So I'm trying to open a maximized Window on my secondary monitor. It all works fine, except it's height is 2 pixels lower than it should be.
My secondary monitor has a resolution of 1280x1024. However once I inspect the window, it's 1280x1022. Does anyone know the problem?
OS: Windows 10
Actual height/width image (Puush)
Here is some code:
SecondaryMonitorWindow smw = new SecondaryMonitorWindow();
smw.Show();
XAML
Loaded="OnWindowLoaded"
WindowStartupLocation="Manual"
WindowStyle="None"
SnapsToDevicePixels="True"
Height="1280"
Width="1024"
Constructor
public SecondaryMonitorWindow()
{
InitializeComponent();
Instance = this;
}
Event
private void OnWindowLoaded(object sender, RoutedEventArgs e)
{
this.MaximizeToSecondaryMonitor();
}
ExtensionMethod
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;
}
}