From 1cd7f34a65fbb1346851b684cbbfcdcde5725a47 Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 18 Jul 2024 23:47:16 +0800 Subject: [PATCH 1/2] Proof of Concept: AppWindowPresenter page --- WinUIGallery/ControlPages/AppWindowPage.xaml | 38 ++++++++++ .../ControlPages/AppWindowPage.xaml.cs | 58 ++++++++++++++ WinUIGallery/DataModel/ControlInfoData.json | 58 +++++++++----- .../SampleCompactOverlayPresenterWindow.xaml | 15 ++++ ...ampleCompactOverlayPresenterWindow.xaml.cs | 47 ++++++++++++ .../SampleFullScreenPresenterWindow.xaml | 14 ++++ .../SampleFullScreenPresenterWindow.xaml.cs | 38 ++++++++++ .../SampleOverlappedPresenterWindow.xaml | 20 +++++ .../SampleOverlappedPresenterWindow.xaml.cs | 76 +++++++++++++++++++ WinUIGallery/WinUIGallery.csproj | 24 ++++++ 10 files changed, 368 insertions(+), 20 deletions(-) create mode 100644 WinUIGallery/ControlPages/AppWindowPage.xaml create mode 100644 WinUIGallery/ControlPages/AppWindowPage.xaml.cs create mode 100644 WinUIGallery/SamplePages/SampleCompactOverlayPresenterWindow.xaml create mode 100644 WinUIGallery/SamplePages/SampleCompactOverlayPresenterWindow.xaml.cs create mode 100644 WinUIGallery/SamplePages/SampleFullScreenPresenterWindow.xaml create mode 100644 WinUIGallery/SamplePages/SampleFullScreenPresenterWindow.xaml.cs create mode 100644 WinUIGallery/SamplePages/SampleOverlappedPresenterWindow.xaml create mode 100644 WinUIGallery/SamplePages/SampleOverlappedPresenterWindow.xaml.cs diff --git a/WinUIGallery/ControlPages/AppWindowPage.xaml b/WinUIGallery/ControlPages/AppWindowPage.xaml new file mode 100644 index 000000000..1ec91a383 --- /dev/null +++ b/WinUIGallery/ControlPages/AppWindowPage.xaml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + Create new Window with CompactOverlayPresenter + + + + + + + + + + + diff --git a/WinUIGallery/ControlPages/AppWindowPage.xaml.cs b/WinUIGallery/ControlPages/AppWindowPage.xaml.cs new file mode 100644 index 000000000..30534c757 --- /dev/null +++ b/WinUIGallery/ControlPages/AppWindowPage.xaml.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; +using Microsoft.UI.Xaml.Data; +using Microsoft.UI.Xaml.Input; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Navigation; +using Windows.Foundation; +using Windows.Foundation.Collections; +using WinUIGallery.SamplePages; + +// To learn more about WinUI, the WinUI project structure, +// and more about our project templates, see: http://aka.ms/winui-project-info. + +namespace WinUIGallery.ControlPages +{ + /// + /// An empty page that can be used on its own or navigated to within a Frame. + /// + public sealed partial class AppWindowPage : Page + { + public AppWindowPage() + { + this.InitializeComponent(); + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + new SampleOverlappedPresenterWindow().Activate(); + } + + private void CreateWithFullScreenPresenterButton_Click(object sender, RoutedEventArgs e) + { + new SampleFullScreenPresenterWindow().Activate(); + } + + private void CreateWithCompactOverlayPresenterMenu_Click(object sender, RoutedEventArgs e) + { + switch((sender as MenuFlyoutItem).Tag) + { + case "Large": + new SampleCompactOverlayPresenterWindow(Microsoft.UI.Windowing.CompactOverlaySize.Large).Activate(); + break; + case "Medium": + new SampleCompactOverlayPresenterWindow(Microsoft.UI.Windowing.CompactOverlaySize.Medium).Activate(); + break; + case "Small": + new SampleCompactOverlayPresenterWindow(Microsoft.UI.Windowing.CompactOverlaySize.Small).Activate(); + break; + } + } + } +} diff --git a/WinUIGallery/DataModel/ControlInfoData.json b/WinUIGallery/DataModel/ControlInfoData.json index 43bcb5cd3..42efa0c4c 100644 --- a/WinUIGallery/DataModel/ControlInfoData.json +++ b/WinUIGallery/DataModel/ControlInfoData.json @@ -2843,26 +2843,44 @@ ] }, { - "UniqueId": "TitleBar", - "Title": "TitleBar", - "ApiNamespace": "Microsoft.UI.Xaml", - "Subtitle": "An example showing a custom UIElement used as the titlebar for the app's window.", - "ImagePath": "ms-appx:///Assets/ControlImages/TitleBar.png", - "Description": "This sample shows how to use a custom titlebar for the app's window. There are 2 ways of doing it: using default titlebar and setting an UIElement as a custom titlebar.", - "Content": "

Look at the TitleBarPage.xaml file in Visual Studio to see the full code for this page.

", - "IsUpdated": true, - "Docs": [ - { - "Title": "TitleBar - API", - "Uri": "https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.window.extendscontentintotitlebar" - }, - { - "Title": "Guidelines", - "Uri": "https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.window" - } - ], - "RelatedControls": [ - ] + "UniqueId": "TitleBar", + "Title": "TitleBar", + "ApiNamespace": "Microsoft.UI.Xaml", + "Subtitle": "An example showing a custom UIElement used as the titlebar for the app's window.", + "ImagePath": "ms-appx:///Assets/ControlImages/TitleBar.png", + "Description": "This sample shows how to use a custom titlebar for the app's window. There are 2 ways of doing it: using default titlebar and setting an UIElement as a custom titlebar.", + "Content": "

Look at the TitleBarPage.xaml file in Visual Studio to see the full code for this page.

", + "IsUpdated": true, + "Docs": [ + { + "Title": "TitleBar - API", + "Uri": "https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.window.extendscontentintotitlebar" + }, + { + "Title": "Guidelines", + "Uri": "https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.window" + } + ], + "RelatedControls": [ + ] + }, + { + "UniqueId": "AppWindow", + "Title": "AppWindow", + "ApiNamespace": "Microsoft.UI.Windowing", + "Subtitle": "", + "ImagePath": "ms-appx:///Assets/ControlImages/TitleBar.png", + "Description": "This sample shows different functionalities of AppWindow and its corresponding Presenter.", + "Docs": [ + { + "Title": "AppWindow - API", + "Uri": "https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.windowing.appwindow" + }, + { + "Title": "OverlappedPresenter - API", + "Uri": "https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.windowing.overlappedpresenter" + } + ] } ] }, diff --git a/WinUIGallery/SamplePages/SampleCompactOverlayPresenterWindow.xaml b/WinUIGallery/SamplePages/SampleCompactOverlayPresenterWindow.xaml new file mode 100644 index 000000000..80d71b529 --- /dev/null +++ b/WinUIGallery/SamplePages/SampleCompactOverlayPresenterWindow.xaml @@ -0,0 +1,15 @@ + + + + + Current CompactOverlaySize: + + + diff --git a/WinUIGallery/SamplePages/SampleCompactOverlayPresenterWindow.xaml.cs b/WinUIGallery/SamplePages/SampleCompactOverlayPresenterWindow.xaml.cs new file mode 100644 index 000000000..cf868342b --- /dev/null +++ b/WinUIGallery/SamplePages/SampleCompactOverlayPresenterWindow.xaml.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Microsoft.UI.Windowing; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; +using Microsoft.UI.Xaml.Data; +using Microsoft.UI.Xaml.Input; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Navigation; +using Windows.Foundation; +using Windows.Foundation.Collections; + +// To learn more about WinUI, the WinUI project structure, +// and more about our project templates, see: http://aka.ms/winui-project-info. + +namespace WinUIGallery.SamplePages +{ + /// + /// An empty window that can be used on its own or navigated to within a Frame. + /// + public sealed partial class SampleCompactOverlayPresenterWindow : Window + { + public SampleCompactOverlayPresenterWindow(CompactOverlaySize size) + { + this.InitializeComponent(); + var presenter = CompactOverlayPresenter.Create(); + presenter.InitialSize = size; + AppWindow.SetPresenter(presenter); + SizeText.Text = sizeText(size); + } + + private static string sizeText(CompactOverlaySize size) + { + switch (size) + { + case CompactOverlaySize.Large: return "Large"; + case CompactOverlaySize.Medium: return "Medium"; + case CompactOverlaySize.Small: return "Small"; + } + return ""; + } + } +} diff --git a/WinUIGallery/SamplePages/SampleFullScreenPresenterWindow.xaml b/WinUIGallery/SamplePages/SampleFullScreenPresenterWindow.xaml new file mode 100644 index 000000000..96380c8c3 --- /dev/null +++ b/WinUIGallery/SamplePages/SampleFullScreenPresenterWindow.xaml @@ -0,0 +1,14 @@ + + + + + + + diff --git a/WinUIGallery/SamplePages/SampleFullScreenPresenterWindow.xaml.cs b/WinUIGallery/SamplePages/SampleFullScreenPresenterWindow.xaml.cs new file mode 100644 index 000000000..9c1de5b79 --- /dev/null +++ b/WinUIGallery/SamplePages/SampleFullScreenPresenterWindow.xaml.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; +using Microsoft.UI.Xaml.Data; +using Microsoft.UI.Xaml.Input; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Navigation; +using Windows.Foundation; +using Windows.Foundation.Collections; +using Microsoft.UI.Windowing; + +// To learn more about WinUI, the WinUI project structure, +// and more about our project templates, see: http://aka.ms/winui-project-info. + +namespace WinUIGallery.SamplePages +{ + /// + /// An empty window that can be used on its own or navigated to within a Frame. + /// + public sealed partial class SampleFullScreenPresenterWindow : Window + { + public SampleFullScreenPresenterWindow() + { + this.InitializeComponent(); + AppWindow.SetPresenter(FullScreenPresenter.Create()); + } + + private void CloseWindowButton_Click(object sender, RoutedEventArgs e) + { + Close(); + } + } +} diff --git a/WinUIGallery/SamplePages/SampleOverlappedPresenterWindow.xaml b/WinUIGallery/SamplePages/SampleOverlappedPresenterWindow.xaml new file mode 100644 index 000000000..6f64fea6f --- /dev/null +++ b/WinUIGallery/SamplePages/SampleOverlappedPresenterWindow.xaml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + diff --git a/WinUIGallery/SamplePages/SampleOverlappedPresenterWindow.xaml.cs b/WinUIGallery/SamplePages/SampleOverlappedPresenterWindow.xaml.cs new file mode 100644 index 000000000..19e9b6d59 --- /dev/null +++ b/WinUIGallery/SamplePages/SampleOverlappedPresenterWindow.xaml.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Microsoft.UI.Windowing; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; +using Microsoft.UI.Xaml.Data; +using Microsoft.UI.Xaml.Input; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Navigation; +using Windows.Foundation; +using Windows.Foundation.Collections; + +// To learn more about WinUI, the WinUI project structure, +// and more about our project templates, see: http://aka.ms/winui-project-info. + +namespace WinUIGallery.SamplePages +{ + /// + /// An empty window that can be used on its own or navigated to within a Frame. + /// + public sealed partial class SampleOverlappedPresenterWindow : Window + { + OverlappedPresenter presenter; + public SampleOverlappedPresenterWindow() + { + this.InitializeComponent(); + presenter = AppWindow.Presenter as OverlappedPresenter; + } + + public bool HasBorder + { + get => presenter.HasBorder; + set => presenter.SetBorderAndTitleBar(value, HasTitleBar); + } + + public bool HasTitleBar + { + get => presenter.HasTitleBar; + set => presenter.SetBorderAndTitleBar(HasBorder, value); + } + + public bool IsAlwaysOnTop + { + get => presenter.IsAlwaysOnTop; + set => presenter.IsAlwaysOnTop = value; + } + + public bool IsMaximizable + { + get => presenter.IsMaximizable; + set => presenter.IsMaximizable = value; + } + + public bool IsMinimizable + { + get => presenter.IsMinimizable; + set => presenter.IsMinimizable = value; + } + + public bool IsModal + { + get => presenter.IsModal; + set => presenter.IsModal = value; + } + + public bool IsResizable + { + get => presenter.IsResizable; + set => presenter.IsResizable = value; + } + } +} diff --git a/WinUIGallery/WinUIGallery.csproj b/WinUIGallery/WinUIGallery.csproj index 8b66b6f05..34dc6a5ac 100644 --- a/WinUIGallery/WinUIGallery.csproj +++ b/WinUIGallery/WinUIGallery.csproj @@ -151,6 +151,7 @@ + @@ -170,6 +171,9 @@ + + + @@ -292,6 +296,26 @@ + + + MSBuild:Compile + + + + + MSBuild:Compile + + + + + MSBuild:Compile + + + + + MSBuild:Compile + +