From b96155be731aee3039a44d6febbdfb59a646c024 Mon Sep 17 00:00:00 2001 From: Daniel Clark Date: Mon, 15 Feb 2021 15:19:57 +0000 Subject: [PATCH] Moved EntranceThemeTransition and ThemeShadow to the Presenter style, this allows the margin to be set around the content of the shadow thus allowing you to offset the flyout via the margin property --- samples/NotificationFlyoutSample/Shell.xaml | 1 + .../NotificationFlyoutHost.cs | 33 +++------------- .../NotificationFlyoutHost.xaml | 34 ++++++----------- .../NotificationFlyoutPresenter.cs | 19 ++++++++-- .../NotificationFlyoutPresenter.xaml | 38 ++++++++++++++++++- 5 files changed, 71 insertions(+), 54 deletions(-) diff --git a/samples/NotificationFlyoutSample/Shell.xaml b/samples/NotificationFlyoutSample/Shell.xaml index 909ae1f..1e77c15 100644 --- a/samples/NotificationFlyoutSample/Shell.xaml +++ b/samples/NotificationFlyoutSample/Shell.xaml @@ -8,6 +8,7 @@ diff --git a/src/TheXamlGuy.NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutHost/NotificationFlyoutHost.cs b/src/TheXamlGuy.NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutHost/NotificationFlyoutHost.cs index c61b741..fd06a9c 100644 --- a/src/TheXamlGuy.NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutHost/NotificationFlyoutHost.cs +++ b/src/TheXamlGuy.NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutHost/NotificationFlyoutHost.cs @@ -20,11 +20,8 @@ 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); @@ -49,8 +46,8 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls public void SetFlyoutPlacement(string placement) { - _placement = placement; - UpdateFlyoutVisualState(); + if (_notificationFlyoutPresenter == null) return; + _notificationFlyoutPresenter.UpdatePlacementVisualState(placement); } public void SetOwningFlyout(NotificationFlyout flyout) @@ -96,7 +93,6 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls public void UpdateTheme(bool isColorPrevalence) { - _isColorPrevalence = isColorPrevalence; if (_notificationFlyoutPresenter == null) return; _notificationFlyoutPresenter.UpdateThemeVisualState(isColorPrevalence); } @@ -104,9 +100,11 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls protected override void OnApplyTemplate() { _notificationFlyoutPresenter = GetTemplateChild("NotificationFlyoutPresenter") as NotificationFlyoutPresenter; - _notificationFlyoutPresenter.ApplyTemplate(); - _notificationFlyoutPresenter.UpdateThemeVisualState(_isColorPrevalence); + if (_notificationFlyoutPresenter != null) + { + _notificationFlyoutPresenter.ApplyTemplate(); + } _flyout = GetTemplateChild("Flyout") as Flyout; if (_flyout != null) @@ -123,17 +121,6 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls } _root = GetTemplateChild("Root") as Grid; - if (GetTemplateChild("ContentRoot") is Grid contentRoot) - { - contentRoot.Shadow = new ThemeShadow(); - - var currentTranslation = contentRoot.Translation; - var translation = new Vector3(currentTranslation.X, currentTranslation.Y, 16.0f); - contentRoot.Translation = translation; - } - - _isLoaded = true; - UpdateFlyoutVisualState(); } private void OnFlyoutClosed(object sender, object args) => _notificationFlyout?.InvokeClosedEvent(args); @@ -143,13 +130,5 @@ 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 ea585ab..6e87154 100644 --- a/src/TheXamlGuy.NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutHost/NotificationFlyoutHost.xaml +++ b/src/TheXamlGuy.NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutHost/NotificationFlyoutHost.xaml @@ -54,20 +54,10 @@ AreOpenCloseAnimationsEnabled="False" FlyoutPresenterStyle="{StaticResource BottomFlyoutPresenterStyle}" ShouldConstrainToRootBounds="False"> - - - - - - - - + @@ -75,29 +65,29 @@ - - + - - + - - + - - + diff --git a/src/TheXamlGuy.NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutPresenter/NotificationFlyoutPresenter.cs b/src/TheXamlGuy.NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutPresenter/NotificationFlyoutPresenter.cs index 1e8d39d..479b79e 100644 --- a/src/TheXamlGuy.NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutPresenter/NotificationFlyoutPresenter.cs +++ b/src/TheXamlGuy.NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutPresenter/NotificationFlyoutPresenter.cs @@ -1,15 +1,28 @@ -using Windows.UI.Xaml; +using System.Numerics; +using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Media; namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls { public class NotificationFlyoutPresenter : ContentControl { - public NotificationFlyoutPresenter() + public NotificationFlyoutPresenter() => DefaultStyleKey = typeof(NotificationFlyoutPresenter); + + protected override void OnApplyTemplate() { - DefaultStyleKey = typeof(NotificationFlyoutPresenter); + if (GetTemplateChild("Root") is Grid contentRoot) + { + contentRoot.Shadow = new ThemeShadow(); + + var currentTranslation = contentRoot.Translation; + var translation = new Vector3(currentTranslation.X, currentTranslation.Y, 16.0f); + contentRoot.Translation = translation; + } } + internal void UpdatePlacementVisualState(string placement) => VisualStateManager.GoToState(this, placement, true); + internal void UpdateThemeVisualState(bool isColorPrevalence) => VisualStateManager.GoToState(this, isColorPrevalence ? "ColorPrevalenceTheme" : "DefaultTheme", true); } } \ No newline at end of file diff --git a/src/TheXamlGuy.NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutPresenter/NotificationFlyoutPresenter.xaml b/src/TheXamlGuy.NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutPresenter/NotificationFlyoutPresenter.xaml index 78dbf0e..349817a 100644 --- a/src/TheXamlGuy.NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutPresenter/NotificationFlyoutPresenter.xaml +++ b/src/TheXamlGuy.NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutPresenter/NotificationFlyoutPresenter.xaml @@ -35,7 +35,7 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -70,7 +104,7 @@ - +