Tunnel flyout events to top level notificationflyout so users can handle events accordingly.
This commit is contained in:
@@ -58,7 +58,7 @@
|
||||
<Slider Margin="0,0,0,8" />
|
||||
<TextBox Margin="0,0,0,8" />
|
||||
<CalendarView Margin="0,0,0,8" />
|
||||
<TimePicker Margin="0,0,0,8" />
|
||||
<TimePicker x:Name="foo" Margin="0,0,0,8" />
|
||||
<DatePicker />
|
||||
<muxc:NumberBox
|
||||
x:Name="NumberBoxSpinButtonPlacementExample"
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace NotificationFlyoutSample
|
||||
using Windows.UI.Xaml.Controls;
|
||||
|
||||
namespace NotificationFlyoutSample
|
||||
{
|
||||
public sealed partial class Shell
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Windows.Foundation;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Markup;
|
||||
using Windows.UI.Xaml.Media;
|
||||
@@ -40,8 +41,12 @@ namespace NotificationFlyout.Uwp.UI.Controls
|
||||
|
||||
private static INotificationFlyoutApplication _applicationInstance;
|
||||
|
||||
internal event EventHandler ContextMenuChanged;
|
||||
public event EventHandler<object> Closed;
|
||||
public event TypedEventHandler<NotificationFlyout, NotificationFlyoutClosingEventArgs> Closing;
|
||||
public event EventHandler<object> Opened;
|
||||
public event EventHandler<object> 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);
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace NotificationFlyout.Uwp.UI.Controls
|
||||
{
|
||||
public sealed class NotificationFlyoutClosingEventArgs : EventArgs
|
||||
{
|
||||
public bool Cancel { get; set; }
|
||||
}
|
||||
}
|
||||
+32
-6
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.Drawing.Common" Version="5.0.0" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="5.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
+2
@@ -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;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Windows.SDK.Contracts" Version="10.0.19041.1" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="5.0.0" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="5.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user