-
Notifications
You must be signed in to change notification settings - Fork 628
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1290 from microsoft/user/karkarl/UpdateMicaSample
Mica Sample Update
- Loading branch information
Showing
13 changed files
with
274 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
WinUIGallery/ControlPagesSampleCode/SystemBackdrops/SystemBackdropsSample3.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Option 2 - Implement Mica with codebehind. | ||
// Allows for toggling backdrops as shown in sample. | ||
bool TrySetMicaBackdrop(bool useMicaAlt) | ||
{ | ||
if (Microsoft.UI.Composition.SystemBackdrops.MicaController.IsSupported()) | ||
{ | ||
Microsoft.UI.Xaml.Media.MicaBackdrop micaBackdrop = new Microsoft.UI.Xaml.Media.MicaBackdrop(); | ||
micaBackdrop.Kind = useMicaAlt ? Microsoft.UI.Composition.SystemBackdrops.MicaKind.BaseAlt : Microsoft.UI.Composition.SystemBackdrops.MicaKind.Base; | ||
this.SystemBackdrop = micaBackdrop; | ||
|
||
return true; // Succeeded. | ||
} | ||
|
||
return false; // Mica is not supported on this system. | ||
} |
14 changes: 14 additions & 0 deletions
14
WinUIGallery/ControlPagesSampleCode/SystemBackdrops/SystemBackdropsSample4.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Option 2 - Implement Acrylic with codebehind. | ||
// Allows for toggling backdrops as shown in sample. | ||
bool TrySetDesktopAcrylicBackdrop() | ||
{ | ||
if (Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicController.IsSupported()) | ||
{ | ||
Microsoft.UI.Xaml.Media.DesktopAcrylicBackdrop DesktopAcrylicBackdrop = new Microsoft.UI.Xaml.Media.DesktopAcrylicBackdrop(); | ||
this.SystemBackdrop = DesktopAcrylicBackdrop; | ||
|
||
return true; // Succeeded. | ||
} | ||
|
||
return false; // DesktopAcrylic is not supported on this system. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
WinUIGallery/SamplePages/SampleBuiltInSystemBackdropsWindow.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<Window | ||
x:Class="AppUIBasics.SamplePages.SampleBuiltInSystemBackdropsWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d"> | ||
|
||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="32" /> | ||
<RowDefinition Height="*" /> | ||
</Grid.RowDefinitions> | ||
<Grid x:Name="titleBar" Background="Transparent" /> | ||
<StackPanel | ||
Grid.Row="1" | ||
HorizontalAlignment="Center" | ||
VerticalAlignment="Center" | ||
Spacing="12"> | ||
<TextBlock HorizontalAlignment="Center"> | ||
<Run Text="Current backdrop: " /> | ||
<Run x:Name="tbCurrentBackdrop" FontWeight="SemiBold" /> | ||
</TextBlock> | ||
<Button | ||
x:Name="btnChangeBackdrop" | ||
HorizontalAlignment="Center" | ||
Click="ChangeBackdropButton_Click" | ||
Content="Change Backdrop" /> | ||
<TextBlock x:Name="tbChangeStatus" HorizontalAlignment="Center" /> | ||
</StackPanel> | ||
</Grid> | ||
</Window> |
129 changes: 129 additions & 0 deletions
129
WinUIGallery/SamplePages/SampleBuiltInSystemBackdropsWindow.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
using AppUIBasics.Helper; | ||
using Microsoft.UI.Xaml; | ||
|
||
namespace AppUIBasics.SamplePages | ||
{ | ||
public sealed partial class SampleBuiltInSystemBackdropsWindow : Window | ||
{ | ||
BackdropType m_currentBackdrop; | ||
|
||
public SampleBuiltInSystemBackdropsWindow() | ||
{ | ||
this.InitializeComponent(); | ||
((FrameworkElement)this.Content).RequestedTheme = AppUIBasics.Helper.ThemeHelper.RootTheme; | ||
ExtendsContentIntoTitleBar = true; | ||
SetTitleBar(titleBar); | ||
SetBackdrop(BackdropType.Mica); | ||
} | ||
|
||
|
||
public enum BackdropType | ||
{ | ||
Mica, | ||
MicaAlt, | ||
DesktopAcrylic, | ||
DefaultColor, | ||
} | ||
|
||
public void SetBackdrop(BackdropType type) | ||
{ | ||
// Reset to default color. If the requested type is supported, we'll update to that. | ||
// Note: This sample completely removes any previous controller to reset to the default | ||
// state. This is done so this sample can show what is expected to be the most | ||
// common pattern of an app simply choosing one controller type which it sets at | ||
// startup. If an app wants to toggle between Mica and Acrylic it could simply | ||
// call RemoveSystemBackdropTarget() on the old controller and then setup the new | ||
// controller, reusing any existing m_configurationSource and Activated/Closed | ||
// event handlers. | ||
m_currentBackdrop = BackdropType.DefaultColor; | ||
tbCurrentBackdrop.Text = "None (default theme color)"; | ||
tbChangeStatus.Text = ""; | ||
this.SystemBackdrop = null; | ||
|
||
if (type == BackdropType.Mica) | ||
{ | ||
if (TrySetMicaBackdrop(false)) | ||
{ | ||
tbCurrentBackdrop.Text = "Built-in Mica"; | ||
m_currentBackdrop = type; | ||
} | ||
else | ||
{ | ||
// Mica isn't supported. Try Acrylic. | ||
type = BackdropType.DesktopAcrylic; | ||
tbChangeStatus.Text += " Mica isn't supported. Trying Acrylic."; | ||
} | ||
} | ||
if (type == BackdropType.MicaAlt) | ||
{ | ||
if (TrySetMicaBackdrop(true)) | ||
{ | ||
tbCurrentBackdrop.Text = "Built-in MicaAlt"; | ||
m_currentBackdrop = type; | ||
} | ||
else | ||
{ | ||
// MicaAlt isn't supported. Try Acrylic. | ||
type = BackdropType.DesktopAcrylic; | ||
tbChangeStatus.Text += " MicaAlt isn't supported. Trying Acrylic."; | ||
} | ||
} | ||
if (type == BackdropType.DesktopAcrylic) | ||
{ | ||
if (TrySetAcrylicBackdrop()) | ||
{ | ||
tbCurrentBackdrop.Text = "Built-in Acrylic"; | ||
m_currentBackdrop = type; | ||
} | ||
else | ||
{ | ||
// Acrylic isn't supported, so take the next option, which is DefaultColor, which is already set. | ||
tbChangeStatus.Text += " Acrylic isn't supported. Switching to default color."; | ||
} | ||
} | ||
|
||
// Announce visual change to automation. | ||
UIHelper.AnnounceActionForAccessibility(btnChangeBackdrop, $"Background changed to {tbCurrentBackdrop.Text}", "BackgroundChangedNotificationActivityId"); | ||
} | ||
|
||
bool TrySetMicaBackdrop(bool useMicaAlt) | ||
{ | ||
if (Microsoft.UI.Composition.SystemBackdrops.MicaController.IsSupported()) | ||
{ | ||
Microsoft.UI.Xaml.Media.MicaBackdrop micaBackdrop = new Microsoft.UI.Xaml.Media.MicaBackdrop(); | ||
micaBackdrop.Kind = useMicaAlt ? Microsoft.UI.Composition.SystemBackdrops.MicaKind.BaseAlt : Microsoft.UI.Composition.SystemBackdrops.MicaKind.Base; | ||
this.SystemBackdrop = micaBackdrop; | ||
return true; | ||
} | ||
|
||
return false; // Mica is not supported on this system | ||
} | ||
|
||
bool TrySetAcrylicBackdrop() | ||
{ | ||
if (Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicController.IsSupported()) | ||
{ | ||
this.SystemBackdrop = new Microsoft.UI.Xaml.Media.DesktopAcrylicBackdrop(); | ||
return true; | ||
} | ||
|
||
return false; // Acrylic is not supported on this system | ||
} | ||
|
||
void ChangeBackdropButton_Click(object sender, RoutedEventArgs e) | ||
{ | ||
BackdropType newType; | ||
|
||
switch (m_currentBackdrop) | ||
{ | ||
case BackdropType.Mica: newType = BackdropType.MicaAlt; break; | ||
case BackdropType.MicaAlt: newType = BackdropType.DesktopAcrylic; break; | ||
case BackdropType.DesktopAcrylic: newType = BackdropType.DefaultColor; break; | ||
default: | ||
case BackdropType.DefaultColor: newType = BackdropType.Mica; break; | ||
} | ||
|
||
SetBackdrop(newType); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.