diff --git a/samples/NotificationFlyoutSample/Shell.xaml b/samples/NotificationFlyoutSample/Shell.xaml index b971c0c..b1cfc88 100644 --- a/samples/NotificationFlyoutSample/Shell.xaml +++ b/samples/NotificationFlyoutSample/Shell.xaml @@ -58,7 +58,7 @@ - + Closed; + public event TypedEventHandler Closing; + public event EventHandler Opened; + public event EventHandler Opening; + internal event EventHandler ContextMenuChanged; internal event EventHandler IconSourceChanged; public UIElement Content @@ -84,6 +89,14 @@ namespace NotificationFlyout.Uwp.UI.Controls internal static void SetApplication(INotificationFlyoutApplication application) => _applicationInstance = application; + internal void InvokeClosedEvent(object obj) => Closed?.Invoke(this, obj); + + internal void InvokeClosingEvent(NotificationFlyoutClosingEventArgs eventArgs) => Closing?.Invoke(this, eventArgs); + + internal void InvokeOpenedEvent(object obj) => Opened?.Invoke(this, obj); + + internal void InvokeOpeningEvent(object obj) => Opening?.Invoke(this, obj); + private static void OnContextMenuPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args) { var sender = dependencyObject as NotificationFlyout; @@ -96,14 +109,8 @@ namespace NotificationFlyout.Uwp.UI.Controls sender?.OnIconPropertyChanged(); } - private void OnContextMenuPropertyChanged() - { - ContextMenuChanged?.Invoke(this, EventArgs.Empty); - } + private void OnContextMenuPropertyChanged() => ContextMenuChanged?.Invoke(this, EventArgs.Empty); - private void OnIconPropertyChanged() - { - IconSourceChanged?.Invoke(this, EventArgs.Empty); - } + private void OnIconPropertyChanged() => IconSourceChanged?.Invoke(this, EventArgs.Empty); } } \ No newline at end of file diff --git a/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/NotificationFlyoutClosingEventArgs.cs b/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/NotificationFlyoutClosingEventArgs.cs new file mode 100644 index 0000000..668b6af --- /dev/null +++ b/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/NotificationFlyoutClosingEventArgs.cs @@ -0,0 +1,9 @@ +using System; + +namespace NotificationFlyout.Uwp.UI.Controls +{ + public sealed class NotificationFlyoutClosingEventArgs : EventArgs + { + public bool Cancel { get; set; } + } +} \ No newline at end of file diff --git a/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/NotificationFlyoutHost.cs b/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/NotificationFlyoutHost.cs index 752a9c4..c25a04b 100644 --- a/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/NotificationFlyoutHost.cs +++ b/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/NotificationFlyoutHost.cs @@ -19,10 +19,10 @@ namespace NotificationFlyout.Uwp.UI.Controls typeof(Style), typeof(NotificationFlyoutHost), new PropertyMetadata(null)); + private Flyout _flyout; private bool _isLoaded; - + private NotificationFlyout _notificationFlyout; private string _placement; - private Grid _root; public NotificationFlyoutHost() => DefaultStyleKey = typeof(NotificationFlyoutHost); @@ -38,6 +38,7 @@ namespace NotificationFlyout.Uwp.UI.Controls get => (Style)GetValue(FlyoutPresenterStyleProperty); set => SetValue(FlyoutPresenterStyleProperty, value); } + public void HideFlyout() { if (_root == null) return; @@ -63,16 +64,18 @@ namespace NotificationFlyout.Uwp.UI.Controls flyout.ShowAt(_root, new FlyoutShowOptions { Placement = placementMode, - ShowMode = FlyoutShowMode.Standard, + ShowMode = FlyoutShowMode.Transient, }); } internal void SetOwningFlyout(NotificationFlyout flyout) { + _notificationFlyout = flyout; + BindingOperations.SetBinding(this, ContentProperty, new Binding { - Source = flyout, + Source = _notificationFlyout, Path = new PropertyPath(nameof(Content)), Mode = BindingMode.TwoWay @@ -81,7 +84,7 @@ namespace NotificationFlyout.Uwp.UI.Controls BindingOperations.SetBinding(this, RequestedThemeProperty, new Binding { - Source = flyout, + Source = _notificationFlyout, Path = new PropertyPath(nameof(RequestedTheme)), Mode = BindingMode.TwoWay }); @@ -89,13 +92,28 @@ namespace NotificationFlyout.Uwp.UI.Controls BindingOperations.SetBinding(this, FlyoutPresenterStyleProperty, new Binding { - Source = flyout, + Source = _notificationFlyout, Path = new PropertyPath(nameof(FlyoutPresenterStyle)), Mode = BindingMode.TwoWay }); } + protected override void OnApplyTemplate() { + _flyout = GetTemplateChild("Flyout") as Flyout; + if (_flyout != null) + { + _flyout.Closing -= OnFlyoutClosing; + _flyout.Closed -= OnFlyoutClosed; + _flyout.Opening -= OnFlyoutOpening; + _flyout.Opened -= OnFlyoutOpened; + + _flyout.Closing += OnFlyoutClosing; + _flyout.Closed += OnFlyoutClosed; + _flyout.Opening += OnFlyoutOpening; + _flyout.Opened += OnFlyoutOpened; + } + _root = GetTemplateChild("Root") as Grid; if (GetTemplateChild("ContentRoot") is Grid contentRoot) { @@ -109,5 +127,13 @@ namespace NotificationFlyout.Uwp.UI.Controls _isLoaded = true; SetFlyoutPlacement(_placement); } + + private void OnFlyoutClosed(object sender, object args) => _notificationFlyout?.InvokeClosedEvent(args); + + private void OnFlyoutClosing(FlyoutBase sender, FlyoutBaseClosingEventArgs args) => _notificationFlyout?.InvokeClosingEvent(new NotificationFlyoutClosingEventArgs()); + + private void OnFlyoutOpened(object sender, object args) => _notificationFlyout?.InvokeOpenedEvent(args); + + private void OnFlyoutOpening(object sender, object args) => _notificationFlyout?.InvokeOpeningEvent(args); } } \ No newline at end of file diff --git a/src/NotificationFlyout.Uwp.UI/NotificationFlyout.Uwp.UI.csproj b/src/NotificationFlyout.Uwp.UI/NotificationFlyout.Uwp.UI.csproj index 325739e..4996447 100644 --- a/src/NotificationFlyout.Uwp.UI/NotificationFlyout.Uwp.UI.csproj +++ b/src/NotificationFlyout.Uwp.UI/NotificationFlyout.Uwp.UI.csproj @@ -32,7 +32,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + \ No newline at end of file diff --git a/src/NotificationFlyout.Wpf.UI.Controls/NotificationFlyout/NotificationFlyoutXamlHost.cs b/src/NotificationFlyout.Wpf.UI.Controls/NotificationFlyout/NotificationFlyoutXamlHost.cs index 0186d34..b69e9a3 100644 --- a/src/NotificationFlyout.Wpf.UI.Controls/NotificationFlyout/NotificationFlyoutXamlHost.cs +++ b/src/NotificationFlyout.Wpf.UI.Controls/NotificationFlyout/NotificationFlyoutXamlHost.cs @@ -128,6 +128,7 @@ namespace NotificationFlyout.Wpf.UI.Controls _contextMenuXamlHost.SetOwningFlyout(_flyout); } + private void PrepareNotificationIcon() { _notificationIconHelper = NotificationIconHelper.Create(this); @@ -150,6 +151,7 @@ namespace NotificationFlyout.Wpf.UI.Controls if (_contextMenuXamlHost == null) return; _contextMenuXamlHost.ShowContextMenuFlyout(); } + private async void UpdateIcons() { if (!IsLoaded) return; diff --git a/src/NotificationFlyout.Wpf.UI/NotificationFlyout.Wpf.UI.csproj b/src/NotificationFlyout.Wpf.UI/NotificationFlyout.Wpf.UI.csproj index bc9e9a0..6fa42d6 100644 --- a/src/NotificationFlyout.Wpf.UI/NotificationFlyout.Wpf.UI.csproj +++ b/src/NotificationFlyout.Wpf.UI/NotificationFlyout.Wpf.UI.csproj @@ -17,7 +17,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - +