using Microsoft.UI; using Microsoft.UI.Windowing; using Microsoft.UI.Xaml; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Windows.Graphics; namespace Sonex.Client.Helpers { public static class AppWindowsHelper { public static void CenterWindow(Window window, int width, int height) { var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(window); var windowId = Win32Interop.GetWindowIdFromWindow(hwnd); var appWindow = AppWindow.GetFromWindowId(windowId); var displayArea = DisplayArea.GetFromWindowId( windowId, DisplayAreaFallback.Primary); var x = (displayArea.WorkArea.Width - width) / 2; var y = (displayArea.WorkArea.Height - height) / 2; appWindow.MoveAndResize(new RectInt32(x, y, width, height)); } } }