simplify setting the flyout content
This commit is contained in:
@@ -6,7 +6,5 @@
|
||||
<NotificationFlyout.Icon>
|
||||
<NotificationFlyoutIcon IconSource="/Assets/Icon.ico" />
|
||||
</NotificationFlyout.Icon>
|
||||
<NotificationFlyout.FlyoutContent>
|
||||
<sample:MyUserControl1 />
|
||||
</NotificationFlyout.FlyoutContent>
|
||||
<sample:MyUserControl1 />
|
||||
</NotificationFlyout>
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using NotificationFlyout.Wpf.UI.Extensions;
|
||||
using NotificationFlyout.Wpf.UI.Helpers;
|
||||
using System.Windows;
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace NotificationFlyout.Wpf.UI.Controls
|
||||
{
|
||||
[ContentProperty(nameof(Content))]
|
||||
public class NotificationFlyout : DependencyObject
|
||||
{
|
||||
private const string ShellTrayHandleName = "Shell_TrayWnd";
|
||||
@@ -13,10 +15,10 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
||||
typeof(NotificationFlyoutIcon), typeof(NotificationFlyout),
|
||||
new PropertyMetadata(null, OnIconPropertyChanged));
|
||||
|
||||
public static DependencyProperty FlyoutContentProperty =
|
||||
DependencyProperty.Register(nameof(FlyoutContent),
|
||||
public static DependencyProperty ContentProperty =
|
||||
DependencyProperty.Register(nameof(Content),
|
||||
typeof(Windows.UI.Xaml.UIElement), typeof(NotificationFlyout),
|
||||
new PropertyMetadata(null, OnFlyoutContentPropertyChanged));
|
||||
new PropertyMetadata(null, OnContentPropertyChanged));
|
||||
|
||||
private NotificationFlyoutXamlHost _xamlHost;
|
||||
|
||||
@@ -26,10 +28,10 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
||||
_xamlHost.Show();
|
||||
}
|
||||
|
||||
public Windows.UI.Xaml.UIElement FlyoutContent
|
||||
public Windows.UI.Xaml.UIElement Content
|
||||
{
|
||||
get => (Windows.UI.Xaml.UIElement)GetValue(FlyoutContentProperty);
|
||||
set => SetValue(FlyoutContentProperty, value);
|
||||
get => (Windows.UI.Xaml.UIElement)GetValue(ContentProperty);
|
||||
set => SetValue(ContentProperty, value);
|
||||
}
|
||||
|
||||
public NotificationFlyoutIcon Icon
|
||||
@@ -48,10 +50,10 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
||||
_xamlHost.ShowFlyout();
|
||||
}
|
||||
|
||||
private static void OnFlyoutContentPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
|
||||
private static void OnContentPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
|
||||
{
|
||||
var sender = dependencyObject as NotificationFlyout;
|
||||
sender?.OnFlyoutContentPropertyChanged();
|
||||
sender?.OnContentPropertyChanged();
|
||||
}
|
||||
|
||||
private static void OnIconPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
|
||||
@@ -60,9 +62,9 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
||||
sender?.OnIconPropertyChanged();
|
||||
}
|
||||
|
||||
private void OnFlyoutContentPropertyChanged()
|
||||
private void OnContentPropertyChanged()
|
||||
{
|
||||
_xamlHost.FlyoutContent = FlyoutContent;
|
||||
_xamlHost.SetFlyoutContent(Content);
|
||||
}
|
||||
|
||||
private void OnIconPropertyChanged()
|
||||
|
||||
+7
-28
@@ -3,7 +3,6 @@ using NotificationFlyout.Uwp.UI.Controls;
|
||||
using NotificationFlyout.Wpf.UI.Extensions;
|
||||
using NotificationFlyout.Wpf.UI.Helpers;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using Windows.UI.Xaml.Controls.Primitives;
|
||||
@@ -12,11 +11,7 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
||||
{
|
||||
internal class NotificationFlyoutXamlHost : Window
|
||||
{
|
||||
internal static DependencyProperty FlyoutContentProperty =
|
||||
DependencyProperty.Register(nameof(FlyoutContent),
|
||||
typeof(Windows.UI.Xaml.UIElement), typeof(NotificationFlyoutXamlHost),
|
||||
new PropertyMetadata(null, OnFlyoutContentPropertyChanged));
|
||||
|
||||
private const double MaximumOffset = 80;
|
||||
private WindowsXamlHost _host;
|
||||
|
||||
private NotificationIconHelper _notificationIconHelper;
|
||||
@@ -30,10 +25,13 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
||||
Loaded += OnLoaded;
|
||||
}
|
||||
|
||||
public Windows.UI.Xaml.UIElement FlyoutContent
|
||||
public void SetFlyoutContent(Windows.UI.Xaml.UIElement content)
|
||||
{
|
||||
get => (Windows.UI.Xaml.UIElement)GetValue(FlyoutContentProperty);
|
||||
set => SetValue(FlyoutContentProperty, value);
|
||||
var flyoutPresenter = GetNotificationFlyoutPresenter();
|
||||
if (flyoutPresenter != null)
|
||||
{
|
||||
flyoutPresenter.Content = content;
|
||||
}
|
||||
}
|
||||
|
||||
internal void HideFlyout()
|
||||
@@ -49,9 +47,6 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
||||
{
|
||||
_notificationIconHelper.SetIcon(handle);
|
||||
}
|
||||
|
||||
private const double MaximumOffset = 80;
|
||||
|
||||
internal void ShowFlyout()
|
||||
{
|
||||
var flyoutPresenter = GetNotificationFlyoutPresenter();
|
||||
@@ -72,27 +67,11 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnFlyoutContentPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
|
||||
{
|
||||
var sender = dependencyObject as NotificationFlyoutXamlHost;
|
||||
sender?.OnFlyoutContentPropertyChanged();
|
||||
}
|
||||
|
||||
private NotificationFlyoutPresenter GetNotificationFlyoutPresenter()
|
||||
{
|
||||
if (_host == null) return null;
|
||||
return _host.GetUwpInternalObject() as NotificationFlyoutPresenter;
|
||||
}
|
||||
|
||||
private void OnFlyoutContentPropertyChanged()
|
||||
{
|
||||
var flyoutPresenter = GetNotificationFlyoutPresenter();
|
||||
if (flyoutPresenter != null)
|
||||
{
|
||||
flyoutPresenter.Content = FlyoutContent;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnIconInvoked(object sender, NotificationIconInvokedEventArgs args)
|
||||
{
|
||||
ShowFlyout();
|
||||
|
||||
Reference in New Issue
Block a user