diff --git a/samples/NotificationFlyoutSample/Shell.xaml b/samples/NotificationFlyoutSample/Shell.xaml index 874d8c3..909ae1f 100644 --- a/samples/NotificationFlyoutSample/Shell.xaml +++ b/samples/NotificationFlyoutSample/Shell.xaml @@ -12,7 +12,7 @@ - + diff --git a/src/TheXamlGuy.NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutHost/NotificationFlyoutHost.cs b/src/TheXamlGuy.NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutHost/NotificationFlyoutHost.cs index efb4a54..c61b741 100644 --- a/src/TheXamlGuy.NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutHost/NotificationFlyoutHost.cs +++ b/src/TheXamlGuy.NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutHost/NotificationFlyoutHost.cs @@ -20,11 +20,12 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls new PropertyMetadata(null)); private Flyout _flyout; + private bool _isColorPrevalence; private bool _isLoaded; private NotificationFlyout _notificationFlyout; + private NotificationFlyoutPresenter _notificationFlyoutPresenter; private string _placement; private Grid _root; - public NotificationFlyoutHost() => DefaultStyleKey = typeof(NotificationFlyoutHost); public UIElement Content @@ -48,24 +49,8 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls public void SetFlyoutPlacement(string placement) { - if (!_isLoaded) - { - _placement = placement; - } - - if (string.IsNullOrEmpty(placement)) return; - VisualStateManager.GoToState(this, placement, true); - } - - public void ShowFlyout(FlyoutPlacementMode placementMode) - { - if (_root == null) return; - var flyout = FlyoutBase.GetAttachedFlyout(_root); - flyout.ShowAt(_root, new FlyoutShowOptions - { - Placement = placementMode, - ShowMode = FlyoutShowMode.Transient, - }); + _placement = placement; + UpdateFlyoutVisualState(); } public void SetOwningFlyout(NotificationFlyout flyout) @@ -98,8 +83,31 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls }); } + public void ShowFlyout(FlyoutPlacementMode placementMode) + { + if (_root == null) return; + var flyout = FlyoutBase.GetAttachedFlyout(_root); + flyout.ShowAt(_root, new FlyoutShowOptions + { + Placement = placementMode, + ShowMode = FlyoutShowMode.Transient, + }); + } + + public void UpdateTheme(bool isColorPrevalence) + { + _isColorPrevalence = isColorPrevalence; + if (_notificationFlyoutPresenter == null) return; + _notificationFlyoutPresenter.UpdateThemeVisualState(isColorPrevalence); + } + protected override void OnApplyTemplate() { + _notificationFlyoutPresenter = GetTemplateChild("NotificationFlyoutPresenter") as NotificationFlyoutPresenter; + _notificationFlyoutPresenter.ApplyTemplate(); + + _notificationFlyoutPresenter.UpdateThemeVisualState(_isColorPrevalence); + _flyout = GetTemplateChild("Flyout") as Flyout; if (_flyout != null) { @@ -125,7 +133,7 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls } _isLoaded = true; - SetFlyoutPlacement(_placement); + UpdateFlyoutVisualState(); } private void OnFlyoutClosed(object sender, object args) => _notificationFlyout?.InvokeClosedEvent(args); @@ -135,5 +143,13 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls private void OnFlyoutOpened(object sender, object args) => _notificationFlyout?.InvokeOpenedEvent(args); private void OnFlyoutOpening(object sender, object args) => _notificationFlyout?.InvokeOpeningEvent(args); + + private void UpdateFlyoutVisualState() + { + if (!_isLoaded) return; + + if (string.IsNullOrEmpty(_placement)) return; + VisualStateManager.GoToState(this, _placement, true); + } } } \ No newline at end of file diff --git a/src/TheXamlGuy.NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutHost/NotificationFlyoutHost.xaml b/src/TheXamlGuy.NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutHost/NotificationFlyoutHost.xaml index d93798e..ea585ab 100644 --- a/src/TheXamlGuy.NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutHost/NotificationFlyoutHost.xaml +++ b/src/TheXamlGuy.NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutHost/NotificationFlyoutHost.xaml @@ -64,7 +64,7 @@ diff --git a/src/TheXamlGuy.NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutPresenter/NotificationFlyoutPresenter.cs b/src/TheXamlGuy.NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutPresenter/NotificationFlyoutPresenter.cs index cb76eac..1e8d39d 100644 --- a/src/TheXamlGuy.NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutPresenter/NotificationFlyoutPresenter.cs +++ b/src/TheXamlGuy.NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutPresenter/NotificationFlyoutPresenter.cs @@ -10,8 +10,6 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls DefaultStyleKey = typeof(NotificationFlyoutPresenter); } - // protected override void OnApplyTemplate() => UpdateThemeVisualStates(false); - - // private void UpdateThemeVisualStates(bool useTransition) => VisualStateManager.GoToState(this, _systemPersonalisationHelper.IsColorPrevalence ? "ColorPrevalenceTheme" : "DefaultTheme", useTransition); + internal void UpdateThemeVisualState(bool isColorPrevalence) => VisualStateManager.GoToState(this, isColorPrevalence ? "ColorPrevalenceTheme" : "DefaultTheme", true); } } \ No newline at end of file diff --git a/src/TheXamlGuy.NotificationFlyout.Wpf.UI.Controls/NotificationFlyout/NotificationFlyoutXamlHost.cs b/src/TheXamlGuy.NotificationFlyout.Wpf.UI.Controls/NotificationFlyout/NotificationFlyoutXamlHost.cs index caaaa1e..47aa1ef 100644 --- a/src/TheXamlGuy.NotificationFlyout.Wpf.UI.Controls/NotificationFlyout/NotificationFlyoutXamlHost.cs +++ b/src/TheXamlGuy.NotificationFlyout.Wpf.UI.Controls/NotificationFlyout/NotificationFlyoutXamlHost.cs @@ -83,6 +83,7 @@ namespace TheXamlGuy.NotificationFlyout.Wpf.UI.Controls PrepareNotificationIcon(); PrepareTaskbar(); UpdateWindow(); + UpdateTheme(); } protected override void OnDeactivated(EventArgs args) => HideFlyout(); @@ -106,7 +107,11 @@ namespace TheXamlGuy.NotificationFlyout.Wpf.UI.Controls private void OnTaskbarChanged(object sender, EventArgs args) => UpdateWindow(); - private void OnThemeChanged(object sender, SystemPersonalisationChangedEventArgs args) => UpdateIcons(); + private void OnThemeChanged(object sender, SystemPersonalisationChangedEventArgs args) + { + UpdateTheme(); + UpdateIcons(); + } private void PrepareContextMenu() { @@ -175,6 +180,15 @@ namespace TheXamlGuy.NotificationFlyout.Wpf.UI.Controls } } + private void UpdateTheme() + { + var content = GetHostContent(); + if (content != null) + { + content.UpdateTheme(_systemPersonalisationHelper.IsColorPrevalence); + } + } + private void UpdateWindow() { if (!IsLoaded) return;