Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2776 committed Mar 28, 2024
1 parent 94dd254 commit 361f72b
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/PicView.WPF/UILogic/Sizing/WindowSizing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,23 +271,18 @@ internal static void CenterWindowOnScreen(Window window, bool horizontal = true)
{
window?.Dispatcher.Invoke(() =>
{
var width = window.ActualWidth == 0 ? window.Width : window.ActualWidth;
width = double.IsNaN(width) ? window.MinWidth : width;
var height = window.ActualHeight == 0 ? window.Height : window.ActualHeight;
height = double.IsNaN(height) ? window.MinHeight : height;
var y = Math.Max(MonitorInfo.WorkArea.Y, MonitorInfo.WorkArea.Y + (MonitorInfo.WorkArea.Height * MonitorInfo.DpiScaling - height) / 2);
window.Top = y;
if (horizontal)
{
var height = window.ActualHeight == 0 ? window.Height : window.ActualHeight;
height = double.IsNaN(height) ? window.MinHeight : height;
var width = window.ActualWidth == 0 ? window.Width : window.ActualWidth;
width = double.IsNaN(width) ? window.MinWidth : width;
var x = Math.Max(MonitorInfo.WorkArea.X, MonitorInfo.WorkArea.X + (MonitorInfo.WorkArea.Width * MonitorInfo.DpiScaling - width) / 2);
var y = Math.Max(MonitorInfo.WorkArea.Y, MonitorInfo.WorkArea.Y + (MonitorInfo.WorkArea.Height * MonitorInfo.DpiScaling - height) / 2);
window.Top = y;
window.Left = x;
}
else
{
window.Top = (MonitorInfo.WorkArea.Height * MonitorInfo.DpiScaling - width) / 2 + MonitorInfo.WorkArea.Top;
}
});
}

Expand Down

0 comments on commit 361f72b

Please sign in to comment.