This is just a sample of a .NET 5 APIs that extend the Microsoft.UI.Xaml.Window of WinUI 3 in Reunion 0.5
This code is AS IS. It's just for demo proposals
XAML code snippet:
<WinUI:DesktopWindowx:Class="DesktopWindowSample.MainWindow"
...
xmlns:WinUI="using:WinUIExtensions.Desktop" ... >
<StackPanel>
...
</StackPanel>
</WinUI:DesktopWindow>Code behind in C#
usingMicrosoft.UI.Xaml;usingMicrosoft.UI.Xaml.Controls;usingSystem;usingWinUIExtensions.Desktop;namespaceDesktopWindowSample{publicsealedpartialclassMainWindow:DesktopWindow{publicMainWindow(){this.InitializeComponent();//DesktopWindow Features// Set the Max height and width in effective pixelsthis.MaxHeight=800;this.MaxWidth=1024;// Set the Min height and width in effective pixelsthis.MinHeight=400;this.MinWidth=400;// Set the width and Heigh in effective pixelsthis.Width=600;this.Height=600;// Set the Icon of the window. this.Icon="WinUI3.ico";// Set the placement of the Window top, leftSetWindowPlacement(0,0);//Fire before closing the window so you can cancel the close eventthis.Closing+=MainWindow_Closing;//Fire when the user moves the windowthis.Moving+=MainWindow_Moving;//Fire when the users change the size of the windowthis.Sizing+=MainWindow_Sizing;//Fire when the Dpi of the display that host the window changesthis.DpiChanged+=MainWindow_DpiChanged;//Fire when the orientation (portrait and landscape) of the display that host the window changesthis.OrientationChanged+=MainWindow_OrientationChanged;//Get the heigh and the widthdebugTBox.Text=$" Size (Height: {this.Height } Width: {this.Width })";//Get the List of monitors/displaysvarlist=WinUIExtensions.Desktop.DisplayInformation.GetDisplays();foreach(variteminlist){systemTBox.Text+=$"Display ->"+$"\n Device Name: {item.DeviceName}"+$"\n Work Area: ({item.WorkArea.top},{item.WorkArea.left},{item.WorkArea.bottom},{item.WorkArea.right})"+$"\n ScreenHeight: {item.ScreenHeight}"+$"\n ScreenWidth:{item.ScreenWidth}"+$"\n Effective Pixels: width({item.ScreenEfectiveWidth}), height({item.ScreenEfectiveHeight})"+$"\n Availability {item.Availability}\n\n";}//Get the current DPI of the display that host the windowdpiChangedTBox.Text=$"DPI: {this.Dpi}";}privatevoidMainWindow_OrientationChanged(objectsender,WindowOrientationChangedEventArgse){dpiChangedTBox.Text=$"DPI: {this.Dpi} + Orientation: {e.Orientation.ToString("g")}";}privatevoidMainWindow_DpiChanged(objectsender,WindowDpiChangedEventArgse){dpiChangedTBox.Text=$"DPI Changed:{e.Dpi} - {this.Dpi} ";}privatevoidMainWindow_Sizing(objectsender,WindowSizingEventArgse){varwindowPosition=GetWindowPosition();debugTBox.Text=$"Height: {this.Height } Width: {this.Width }\n "+$"Top: {windowPosition.Top} Left:{windowPosition.Left}";}privatevoidMainWindow_Moving(objectsender,WindowMovingEventArgse){debugTBox.Text=$"Height: {this.Height } Width: {this.Width }\n "+$"Top: {e.NewPosition.Top} Left:{e.NewPosition.Left}";}privateasyncvoidMainWindow_Closing(objectsender,WindowClosingEventArgse){ContentDialogcontentDialog=newContentDialog();contentDialog.Content="Close it?";contentDialog.XamlRoot=this.Content.XamlRoot;contentDialog.PrimaryButtonText="Yes";contentDialog.CloseButtonText="No";contentDialog.IsPrimaryButtonEnabled=true;varr=awaitcontentDialog.ShowAsync();if(r==ContentDialogResult.Primary){// Cancel the close event e.TryCancel();}}//Center the Window on the displayprivatevoidOnCenterClick(objectsender,RoutedEventArgse){SetWindowPlacement(Placement.Center);}//Place the Window on the Top LeftprivatevoidOnTopLeft(objectsender,RoutedEventArgse){SetWindowPlacement(Placement.TopLeftCorner);}//Place the Window on the Bottom LeftprivatevoidOnBottomLeft(objectsender,RoutedEventArgse){SetWindowPlacement(Placement.BottomLeftCorner);}//Maximize the WindowprivatevoidOnMaximize(objectsender,RoutedEventArgse){Maximize();}//Minimize the WindowprivatevoidOnMinimize(objectsender,RoutedEventArgse){Minimize();}//Restore the WindowprivatevoidOnRestore(objectsender,RoutedEventArgse){Restore();}//Bring the Window to the topprivatevoidOnBringToTop(objectsender,RoutedEventArgse){BringToTop();}privatevoidOnClosingApplication(objectsender,RoutedEventArgse){Application.Current.Exit();}}}