-
Notifications
You must be signed in to change notification settings - Fork 708
[ADD] SystemBackdropHost Control Sample Page #2079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,53 @@ | ||||||
| <!-- | ||||||
| //********************************************************* | ||||||
| // | ||||||
| // Copyright (c) Microsoft. All rights reserved. | ||||||
| // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF | ||||||
| // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY | ||||||
| // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR | ||||||
| // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. | ||||||
| // | ||||||
| //********************************************************* | ||||||
| --> | ||||||
| <Page x:Class="WinUIGallery.ControlPages.SystemBackdropHostPage" | ||||||
| xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||||||
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||||||
| xmlns:controls="using:WinUIGallery.Controls" | ||||||
| xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||||||
| xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||||||
| mc:Ignorable="d"> | ||||||
| <StackPanel> | ||||||
| <controls:ControlExample x:Name="Example1" HeaderText="SystemBackdropHost Sample"> | ||||||
| <controls:ControlExample.Example> | ||||||
| <Grid Width="300" Height="200" HorizontalAlignment="Center"> | ||||||
| <SystemBackdropHost x:Name="DynamicBackdropHost" CornerRadius="8"> | ||||||
| <SystemBackdropHost.SystemBackdrop> | ||||||
| <DesktopAcrylicBackdrop /> | ||||||
| </SystemBackdropHost.SystemBackdrop> | ||||||
| </SystemBackdropHost> | ||||||
| <Button HorizontalAlignment="Center" VerticalAlignment="Center" Content="Click Me" /> | ||||||
| </Grid> | ||||||
| </controls:ControlExample.Example> | ||||||
| <controls:ControlExample.Options> | ||||||
| <StackPanel Spacing="12"> | ||||||
| <ComboBox x:Name="BackdropTypeComboBox" Header="Backdrop Type" SelectedIndex="0" SelectionChanged="BackdropTypeComboBox_SelectionChanged"> | ||||||
| <ComboBoxItem Content="Acrylic" Tag="Acrylic" /> | ||||||
| <ComboBoxItem Content="Mica" Tag="Mica" /> | ||||||
| <ComboBoxItem Content="Mica Alt" Tag="MicaAlt" /> | ||||||
| </ComboBox> | ||||||
| <Slider x:Name="CornerRadiusSlider" Header="Corner Radius" Maximum="50" Minimum="0" StepFrequency="1" Value="8" ValueChanged="CornerRadiusSlider_ValueChanged" /> | ||||||
| <TextBlock> | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the sake of simplicity, do we need to plot the value? Why not just the slider? |
||||||
| <Run Text="Current Radius: " /> | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| <Run Text="{x:Bind CornerRadiusSlider.Value, Mode=OneWay}" /> | ||||||
| </TextBlock> | ||||||
| </StackPanel> | ||||||
| </controls:ControlExample.Options> | ||||||
| <controls:ControlExample.XamlSource> | ||||||
| SystemBackdropHost/SystemBackdropHostAcrylic_xaml.txt | ||||||
| </controls:ControlExample.XamlSource> | ||||||
| <controls:ControlExample.Substitutions> | ||||||
| <controls:ControlExampleSubstitution Key="CornerRadius" Value="{x:Bind CornerRadiusSlider.Value, Mode=OneWay}" /> | ||||||
| </controls:ControlExample.Substitutions> | ||||||
| </controls:ControlExample> | ||||||
| </StackPanel> | ||||||
| </Page> | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,65 @@ | ||||||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||||||
| // Licensed under the MIT License. | ||||||
|
|
||||||
| using Microsoft.UI.Xaml; | ||||||
| using Microsoft.UI.Xaml.Controls; | ||||||
| using Microsoft.UI.Xaml.Media; | ||||||
|
|
||||||
| namespace WinUIGallery.ControlPages; | ||||||
|
|
||||||
| public sealed partial class SystemBackdropHostPage : Page | ||||||
| { | ||||||
| public SystemBackdropHostPage() | ||||||
| { | ||||||
| this.InitializeComponent(); | ||||||
| } | ||||||
|
|
||||||
| private void BackdropTypeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) | ||||||
| { | ||||||
| if (DynamicBackdropHost == null || BackdropTypeComboBox == null) | ||||||
| return; | ||||||
|
|
||||||
| var selectedItem = BackdropTypeComboBox.SelectedItem as ComboBoxItem; | ||||||
| if (selectedItem == null) | ||||||
| return; | ||||||
|
|
||||||
| string backdropType = selectedItem.Tag?.ToString() ?? "Acrylic"; | ||||||
|
|
||||||
| // Update the SystemBackdrop based on selection | ||||||
| if (backdropType == "Acrylic") | ||||||
| { | ||||||
| DynamicBackdropHost.SystemBackdrop = new DesktopAcrylicBackdrop(); | ||||||
| // Update the sample code source | ||||||
| if (Example1 != null) | ||||||
| { | ||||||
| Example1.XamlSource = "SystemBackdropHost/SystemBackdropHostAcrylic_xaml.txt"; | ||||||
| } | ||||||
| } | ||||||
| else if (backdropType == "Mica") | ||||||
| { | ||||||
| DynamicBackdropHost.SystemBackdrop = new MicaBackdrop { Kind = Microsoft.UI.Composition.SystemBackdrops.MicaKind.Base }; | ||||||
| // Update the sample code source | ||||||
| if (Example1 != null) | ||||||
| { | ||||||
| Example1.XamlSource = "SystemBackdropHost/SystemBackdropHostMica_xaml.txt"; | ||||||
| } | ||||||
| } | ||||||
| else if (backdropType == "MicaAlt") | ||||||
| { | ||||||
| DynamicBackdropHost.SystemBackdrop = new MicaBackdrop { Kind = Microsoft.UI.Composition.SystemBackdrops.MicaKind.BaseAlt }; | ||||||
| // Update the sample code source | ||||||
| if (Example1 != null) | ||||||
| { | ||||||
| Example1.XamlSource = "SystemBackdropHost/SystemBackdropHostMicaAlt_xaml.txt"; | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| private void CornerRadiusSlider_ValueChanged(object sender, Microsoft.UI.Xaml.Controls.Primitives.RangeBaseValueChangedEventArgs e) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes the code cleaner and more consistent with the rest of the file. 🙂
Suggested change
|
||||||
| { | ||||||
| if (DynamicBackdropHost != null) | ||||||
| { | ||||||
| DynamicBackdropHost.CornerRadius = new CornerRadius(e.NewValue); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2658,6 +2658,30 @@ | |
| "Uri": "https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.themeshadow" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "UniqueId": "SystemBackdropHost", | ||
| "Title": "SystemBackdropHost", | ||
| "BaseClasses": [ | ||
| "Object", | ||
| "DependencyObject", | ||
| "UIElement", | ||
| "FrameworkElement", | ||
| "Control", | ||
| "ContentControl" | ||
| ], | ||
| "ApiNamespace": "Microsoft.UI.Xaml.Controls", | ||
| "Subtitle": "A control to host system backdrop materials.", | ||
| "ImagePath": "ms-appx:///Assets/ControlImages/Acrylic.png", | ||
| "Description": "SystemBackdropHost allows you to apply system backdrop materials to specific UI elements.", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May be better to mention 'specific area inside the UI tree' as we are not applying backdrop directly to ui elements |
||
| "Description": "SystemBackdropHost is developed to enable seamless Acrylic effects for individual surfaces and controls in WinUI3 apps. This control allows developers to easily apply system backdrops (like Acrylic and Mica) anywhere in their app UI.", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SystemBackdropHost enables applying Mica and Acrylic to individual UI elements within an app experience, extending these materials beyond the window background for more flexible and immersive designs.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: For consistency, use "WinUI 3" instead of "WinUI3". |
||
| "IsNew": true, | ||
| "Docs": [ | ||
| { | ||
| "Title": "SystemBackdropHost - API", | ||
| "Uri": "https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.systembackdrophost" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,8 @@ | ||||||
| <Grid Width="300" Height="200"> | ||||||
| <SystemBackdropHost CornerRadius="$(CornerRadius)"> | ||||||
| <SystemBackdropHost.SystemBackdrop> | ||||||
| <DesktopAcrylicBackdrop /> | ||||||
| </SystemBackdropHost.SystemBackdrop> | ||||||
| </SystemBackdropHost> | ||||||
| <Button Content="Click Me" HorizontalAlignment="Center" VerticalAlignment="Center"/> | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| </Grid> | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,8 @@ | ||||||
| <Grid Width="300" Height="200"> | ||||||
| <SystemBackdropHost CornerRadius="$(CornerRadius)"> | ||||||
| <SystemBackdropHost.SystemBackdrop> | ||||||
| <MicaBackdrop Kind="BaseAlt" /> | ||||||
| </SystemBackdropHost.SystemBackdrop> | ||||||
| </SystemBackdropHost> | ||||||
| <Button Content="Click Me" HorizontalAlignment="Center" VerticalAlignment="Center"/> | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| </Grid> | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,8 @@ | ||||||
| <Grid Width="300" Height="200"> | ||||||
| <SystemBackdropHost CornerRadius="$(CornerRadius)"> | ||||||
| <SystemBackdropHost.SystemBackdrop> | ||||||
| <MicaBackdrop Kind="Base" /> | ||||||
| </SystemBackdropHost.SystemBackdrop> | ||||||
| </SystemBackdropHost> | ||||||
| <Button Content="Click Me" HorizontalAlignment="Center" VerticalAlignment="Center"/> | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| </Grid> | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.