-
Notifications
You must be signed in to change notification settings - Fork 619
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
Mica Sample Update #1290
Merged
Merged
Mica Sample Update #1290
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 13 additions & 0 deletions
13
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,13 @@ | ||
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. | ||
} |
12 changes: 12 additions & 0 deletions
12
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,12 @@ | ||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@karkarl I'd include a XAML snippet here as well now that's fully supported? It's probably how most devs would (like) to use it?
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.
What should be in the Xaml snippet? I can't think of anything relevant to mica implementation to put in there.
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.
and
That's the easiest way to add
Mica
orAcrylic
to aWindow
without any code behind.. there was a bug blocking this but was fixed with 1.3.1 - it now works great :-).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.
Added!