Added support for IsColorPrevalence background system accent color
This commit is contained in:
+16
@@ -25,6 +25,12 @@
|
||||
<SolidColorBrush x:Key="NotificationFlyoutPresenterBackgroundBrush" Color="Green" />
|
||||
</ResourceDictionary>
|
||||
</ResourceDictionary.ThemeDictionaries>
|
||||
<AcrylicBrush
|
||||
x:Key="NotificationFlyoutPresenterBackgroundAccentBrush"
|
||||
BackgroundSource="HostBackdrop"
|
||||
FallbackColor="{ThemeResource SystemAccentColorDark1}"
|
||||
TintColor="{ThemeResource SystemAccentColorDark1}"
|
||||
TintOpacity="0.8" />
|
||||
<Style TargetType="controls:NotificationFlyoutContentPresenter">
|
||||
<Setter Property="Background" Value="{ThemeResource NotificationFlyoutPresenterBackgroundBrush}" />
|
||||
<Setter Property="Template">
|
||||
@@ -54,6 +60,16 @@
|
||||
ContentTemplate="{TemplateBinding ContentTemplate}"
|
||||
ContentTransitions="{TemplateBinding ContentTransitions}" />
|
||||
</ScrollViewer>
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup x:Name="ThemeStates">
|
||||
<VisualState x:Name="DefaultTheme" />
|
||||
<VisualState x:Name="ColorPrevalenceTheme">
|
||||
<VisualState.Setters>
|
||||
<Setter Target="Root.Background" Value="{ThemeResource NotificationFlyoutPresenterBackgroundAccentBrush}" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
|
||||
+22
-9
@@ -8,6 +8,7 @@ namespace NotificationFlyout.Uwp.UI.Controls
|
||||
{
|
||||
private NotificationFlyoutContentPresenter _contentPresenter;
|
||||
|
||||
private bool _isColorPrevalence;
|
||||
private ElementTheme _systemTheme;
|
||||
|
||||
public NotificationFlyoutPresenter()
|
||||
@@ -15,11 +16,9 @@ namespace NotificationFlyout.Uwp.UI.Controls
|
||||
DefaultStyleKey = typeof(NotificationFlyoutPresenter);
|
||||
RegisterPropertyChangedCallback(RequestedThemeProperty, RequestedThemePropertyChanged);
|
||||
}
|
||||
|
||||
public void SetBackground(string theme)
|
||||
public void UpdateFlyoutTheme(string theme, bool isColorPrevalence)
|
||||
{
|
||||
if (_contentPresenter == null) return;
|
||||
|
||||
_isColorPrevalence = isColorPrevalence;
|
||||
switch (theme)
|
||||
{
|
||||
case "Dark":
|
||||
@@ -30,18 +29,21 @@ namespace NotificationFlyout.Uwp.UI.Controls
|
||||
break;
|
||||
}
|
||||
|
||||
if (RequestedTheme == ElementTheme.Default)
|
||||
{
|
||||
_contentPresenter.SetValue(RequestedThemeProperty, _systemTheme);
|
||||
}
|
||||
UpdateThemeVisualState();
|
||||
}
|
||||
|
||||
protected override void OnApplyTemplate()
|
||||
{
|
||||
_contentPresenter = GetTemplateChild("ContentPresenter") as NotificationFlyoutContentPresenter;
|
||||
Loaded += OnLoaded;
|
||||
}
|
||||
|
||||
private void RequestedThemePropertyChanged(DependencyObject sender, DependencyProperty dp)
|
||||
private void OnLoaded(object sender, RoutedEventArgs args)
|
||||
{
|
||||
UpdateThemeVisualState();
|
||||
}
|
||||
|
||||
private void RequestedThemePropertyChanged(DependencyObject sender, DependencyProperty dependencyProperty)
|
||||
{
|
||||
if (RequestedTheme == ElementTheme.Default)
|
||||
{
|
||||
@@ -52,5 +54,16 @@ namespace NotificationFlyout.Uwp.UI.Controls
|
||||
_contentPresenter.SetValue(RequestedThemeProperty, RequestedTheme);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateThemeVisualState()
|
||||
{
|
||||
if (_contentPresenter == null) return;
|
||||
if (RequestedTheme == ElementTheme.Default)
|
||||
{
|
||||
_contentPresenter.SetValue(RequestedThemeProperty, _systemTheme);
|
||||
}
|
||||
|
||||
VisualStateManager.GoToState(_contentPresenter, _isColorPrevalence ? "ColorPrevalenceTheme" : "DefaultTheme", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user