diff --git a/WinUIGallery/ControlPages/AppWindowPage.xaml b/WinUIGallery/ControlPages/AppWindowPage.xaml new file mode 100644 index 000000000..48e0c31cc --- /dev/null +++ b/WinUIGallery/ControlPages/AppWindowPage.xaml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + 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..f5fc5cdf7 --- /dev/null +++ b/WinUIGallery/SamplePages/SampleCompactOverlayPresenterWindow.xaml @@ -0,0 +1,20 @@ + + + + + + Current CompactOverlaySize: + + + + ExtendsContentIntoTitleBar + + + diff --git a/WinUIGallery/SamplePages/SampleCompactOverlayPresenterWindow.xaml.cs b/WinUIGallery/SamplePages/SampleCompactOverlayPresenterWindow.xaml.cs new file mode 100644 index 000000000..d57f6c684 --- /dev/null +++ b/WinUIGallery/SamplePages/SampleCompactOverlayPresenterWindow.xaml.cs @@ -0,0 +1,52 @@ +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 ""; + } + + private void ToggleButton_Click(object sender, RoutedEventArgs e) + { + ExtendsContentIntoTitleBar = !ExtendsContentIntoTitleBar; + } + } +} 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..4b399e8b1 --- /dev/null +++ b/WinUIGallery/SamplePages/SampleOverlappedPresenterWindow.xaml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + ExtendsContentIntoTitleBar + + diff --git a/WinUIGallery/SamplePages/SampleOverlappedPresenterWindow.xaml.cs b/WinUIGallery/SamplePages/SampleOverlappedPresenterWindow.xaml.cs new file mode 100644 index 000000000..3f343b53d --- /dev/null +++ b/WinUIGallery/SamplePages/SampleOverlappedPresenterWindow.xaml.cs @@ -0,0 +1,123 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +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, INotifyPropertyChanged + { + OverlappedPresenter presenter; + public event PropertyChangedEventHandler PropertyChanged; + public SampleOverlappedPresenterWindow() + { + presenter = AppWindow.Presenter as OverlappedPresenter; + this.InitializeComponent(); + } + + public bool HasBorder + { + get => presenter.HasBorder; + set + { + try + { + presenter.SetBorderAndTitleBar(value, HasTitleBar); + } + catch (Exception e) + { + ShowExceptionDialog(e.Message); + } + NotifyPropertyChanged("HasBorder"); + NotifyPropertyChanged("HasTitleBar"); + } + } + + public bool HasTitleBar + { + get => presenter.HasTitleBar; + set + { + try + { + presenter.SetBorderAndTitleBar(HasBorder, value); + } + catch (Exception e) + { + ShowExceptionDialog(e.Message); + } + NotifyPropertyChanged("HasTitleBar"); + NotifyPropertyChanged("HasBorder"); + } + } + + 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; + } + + private void ToggleButton_Click(object sender, RoutedEventArgs e) + { + ExtendsContentIntoTitleBar = !ExtendsContentIntoTitleBar; + } + + private void NotifyPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + private void ShowExceptionDialog(string message) + { + new ContentDialog() + { + XamlRoot = this.Content.XamlRoot, + Title = "Exception thrown", + Content = message, + PrimaryButtonText = "OK", + }.ShowAsync(); + } + } +} 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 + +