Ensure the flyout respects the given RequestedTheme... although it doesn't seem to be picking up the theme changes from Windows user settings just yet...

This commit is contained in:
Daniel Clark
2021-02-07 11:22:26 +00:00
parent f4556c8314
commit 61305ca00f
5 changed files with 37 additions and 28 deletions
@@ -3,34 +3,12 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:NotificationFlyout.Uwp.UI.Controls"
CornerRadius="8">
CornerRadius="4"
RequestedTheme="Default">
<Grid
Width="330"
Height="360"
Margin="23">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Text="Quick lauch" />
<GridView Grid.Row="1" HorizontalAlignment="Center">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid Orientation="Horizontal" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<Button
Width="94"
Margin="6,6,3,6"
Content="Test" />
<Button
Width="94"
Margin="3,6,3,6"
Content="Test" />
<Button
Width="94"
Margin="3,6,6,6"
Content="Test" />
</GridView>
<ToggleSwitch x:Name="test" Toggled="ToggleSwitch_Toggled" />
</Grid>
</controls:NotificationFlyoutPresenter>
@@ -6,5 +6,18 @@
{
InitializeComponent();
}
private void ToggleSwitch_Toggled(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
if (test.IsOn)
{
this.RequestedTheme = Windows.UI.Xaml.ElementTheme.Dark;
}
else
{
this.RequestedTheme = Windows.UI.Xaml.ElementTheme.Light;
}
}
}
}
@@ -3,6 +3,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sample="clr-namespace:NotificationFlyout.Sample;assembly=NotificationFlyout.Sample"
IconSource="/Assets/Icon.ico">
IconSource="/Assets/Icon.ico"
LightIconSource="/Assets/Icon.ico">
<sample:NotificationFlyoutPresenter />
</NotificationFlyout>
@@ -2,8 +2,19 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:NotificationFlyout.Uwp.UI.Controls">
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<StaticResource x:Key="NotificationFlyoutPresenterBackground" ResourceKey="SystemControlTransientBackgroundBrush" />
</ResourceDictionary>
<ResourceDictionary x:Key="HighContrast">
<StaticResource x:Key="NotificationFlyoutPresenterBackground" ResourceKey="SystemControlPageBackgroundChromeMediumLowBrush" />
</ResourceDictionary>
<ResourceDictionary x:Key="Light">
<StaticResource x:Key="NotificationFlyoutPresenterBackground" ResourceKey="SystemControlTransientBackgroundBrush" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
<Style TargetType="controls:NotificationFlyoutPresenter">
<Setter Property="Background" Value="{StaticResource SystemControlTransientBackgroundBrush}" />
<Setter Property="Background" Value="{ThemeResource SystemControlTransientBackgroundBrush}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:NotificationFlyoutPresenter">
@@ -81,6 +81,11 @@ namespace NotificationFlyout.Wpf.UI.Controls
}
private void OnIconPropertyChanged()
{
SetIcon();
}
private void SetIcon()
{
var shellTrayHandle = WindowHelper.GetHandle(ShellTrayHandleName);
if (shellTrayHandle == null) return;
@@ -88,8 +93,9 @@ namespace NotificationFlyout.Wpf.UI.Controls
var dpi = WindowHelper.GetDpi(shellTrayHandle);
var iconSource = SystemSettingsHelper.DefaultSystemTheme == SystemTheme.Dark ? IconSource : LightIconSource;
using var icon = iconSource.ConvertToIcon(dpi);
if (iconSource == null) return;
using var icon = iconSource.ConvertToIcon(dpi);
_xamlHost.SetNotificationIcon(icon.Handle);
}
}