Added ability to keep the flyout open on the desktop which can be set via IsLightDismissEnabled DP
This commit is contained in:
+45
-13
@@ -17,8 +17,13 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls
|
|||||||
typeof(ImageSource), typeof(NotificationFlyout),
|
typeof(ImageSource), typeof(NotificationFlyout),
|
||||||
new PropertyMetadata(null, OnIconPropertyChanged));
|
new PropertyMetadata(null, OnIconPropertyChanged));
|
||||||
|
|
||||||
|
public static readonly DependencyProperty IsLightDismissEnabledProperty =
|
||||||
|
DependencyProperty.Register(nameof(IsLightDismissEnabled),
|
||||||
|
typeof(bool), typeof(NotificationFlyout),
|
||||||
|
new PropertyMetadata(true));
|
||||||
|
|
||||||
public static readonly DependencyProperty LightIconSourceProperty =
|
public static readonly DependencyProperty LightIconSourceProperty =
|
||||||
DependencyProperty.Register(nameof(LightIconSource),
|
DependencyProperty.Register(nameof(LightIconSource),
|
||||||
typeof(ImageSource), typeof(NotificationFlyout),
|
typeof(ImageSource), typeof(NotificationFlyout),
|
||||||
new PropertyMetadata(null));
|
new PropertyMetadata(null));
|
||||||
|
|
||||||
@@ -43,6 +48,12 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls
|
|||||||
set => SetValue(IconSourceProperty, value);
|
set => SetValue(IconSourceProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsLightDismissEnabled
|
||||||
|
{
|
||||||
|
get => (bool)GetValue(IsLightDismissEnabledProperty);
|
||||||
|
set => SetValue(IsLightDismissEnabledProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
public ImageSource LightIconSource
|
public ImageSource LightIconSource
|
||||||
{
|
{
|
||||||
get => (ImageSource)GetValue(LightIconSourceProperty);
|
get => (ImageSource)GetValue(LightIconSourceProperty);
|
||||||
@@ -51,6 +62,33 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls
|
|||||||
|
|
||||||
public static INotificationFlyoutApplication GetApplication() => _applicationInstance;
|
public static INotificationFlyoutApplication GetApplication() => _applicationInstance;
|
||||||
|
|
||||||
|
public void Hide()
|
||||||
|
{
|
||||||
|
if (_popup == null)
|
||||||
|
{
|
||||||
|
PreparePopup();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsLightDismissEnabled)
|
||||||
|
{
|
||||||
|
_popup.IsOpen = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Show()
|
||||||
|
{
|
||||||
|
if (_popup == null)
|
||||||
|
{
|
||||||
|
PreparePopup();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_popup.IsOpen)
|
||||||
|
{
|
||||||
|
_popup.Child = _child;
|
||||||
|
_popup.IsOpen = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal static void SetApplication(INotificationFlyoutApplication application) => _applicationInstance = application;
|
internal static void SetApplication(INotificationFlyoutApplication application) => _applicationInstance = application;
|
||||||
|
|
||||||
internal void SetPlacement(double horizontalOffset, double verticalOffset, NotificationFlyoutTaskbarPlacement flyoutTaskbarPlacement)
|
internal void SetPlacement(double horizontalOffset, double verticalOffset, NotificationFlyoutTaskbarPlacement flyoutTaskbarPlacement)
|
||||||
@@ -93,18 +131,6 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls
|
|||||||
|
|
||||||
VisualStateManager.GoToState(this, flyoutTaskbarPlacement.ToString(), true);
|
VisualStateManager.GoToState(this, flyoutTaskbarPlacement.ToString(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Show()
|
|
||||||
{
|
|
||||||
if (_popup == null)
|
|
||||||
{
|
|
||||||
PreparePopup();
|
|
||||||
}
|
|
||||||
|
|
||||||
_popup.Child = _child;
|
|
||||||
_popup.IsOpen = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void ShowContextMenuAt(double x, double y)
|
internal void ShowContextMenuAt(double x, double y)
|
||||||
{
|
{
|
||||||
if (ContextFlyout == null) return;
|
if (ContextFlyout == null) return;
|
||||||
@@ -162,6 +188,12 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls
|
|||||||
|
|
||||||
private void PreparePopup()
|
private void PreparePopup()
|
||||||
{
|
{
|
||||||
|
if (_popup != null)
|
||||||
|
{
|
||||||
|
_popup.Opened -= OnPopupOpened;
|
||||||
|
_popup.Closed -= OnPopupClosed;
|
||||||
|
}
|
||||||
|
|
||||||
_popup = new Popup
|
_popup = new Popup
|
||||||
{
|
{
|
||||||
XamlRoot = XamlRoot,
|
XamlRoot = XamlRoot,
|
||||||
|
|||||||
+16
-9
@@ -21,10 +21,10 @@ namespace TheXamlGuy.NotificationFlyout.Wpf.UI.Controls
|
|||||||
new PropertyMetadata(null, OnFlyoutPropertyChanged));
|
new PropertyMetadata(null, OnFlyoutPropertyChanged));
|
||||||
|
|
||||||
private const string ShellTrayHandleName = "Shell_TrayWnd";
|
private const string ShellTrayHandleName = "Shell_TrayWnd";
|
||||||
private TransparentXamlHost<ContentControl> _notificationFlyoutXamlHost;
|
|
||||||
private readonly NotificationIconHelper _notificationIconHelper;
|
private readonly NotificationIconHelper _notificationIconHelper;
|
||||||
private readonly SystemPersonalisationHelper _systemPersonalisationHelper;
|
private readonly SystemPersonalisationHelper _systemPersonalisationHelper;
|
||||||
private readonly TaskbarHelper _taskbarHelper;
|
private readonly TaskbarHelper _taskbarHelper;
|
||||||
|
private TransparentXamlHost<ContentControl> _notificationFlyoutXamlHost;
|
||||||
|
|
||||||
public NotificationFlyoutApplication()
|
public NotificationFlyoutApplication()
|
||||||
{
|
{
|
||||||
@@ -84,6 +84,8 @@ namespace TheXamlGuy.NotificationFlyout.Wpf.UI.Controls
|
|||||||
|
|
||||||
private void OnIconSourceChanged(object sender, EventArgs args) => UpdateIcons();
|
private void OnIconSourceChanged(object sender, EventArgs args) => UpdateIcons();
|
||||||
|
|
||||||
|
private void OnInteractedWith(object sender, EventArgs args) => _notificationFlyoutXamlHost.Activate();
|
||||||
|
|
||||||
private void OnNotificationFlyoutXamlHostClosed(object sender, EventArgs args) => _notificationIconHelper?.Dispose();
|
private void OnNotificationFlyoutXamlHostClosed(object sender, EventArgs args) => _notificationIconHelper?.Dispose();
|
||||||
|
|
||||||
private void OnTaskbarChanged(object sender, EventArgs args) => UpdateFlyoutPlacement();
|
private void OnTaskbarChanged(object sender, EventArgs args) => UpdateFlyoutPlacement();
|
||||||
@@ -98,7 +100,7 @@ namespace TheXamlGuy.NotificationFlyout.Wpf.UI.Controls
|
|||||||
{
|
{
|
||||||
if (Flyout == null) return;
|
if (Flyout == null) return;
|
||||||
Flyout.IconSourceChanged += OnIconSourceChanged;
|
Flyout.IconSourceChanged += OnIconSourceChanged;
|
||||||
Flyout.InteractedWith += Flyout_Focused; ;
|
Flyout.InteractedWith += OnInteractedWith;
|
||||||
|
|
||||||
var content = _notificationFlyoutXamlHost.GetHostContent();
|
var content = _notificationFlyoutXamlHost.GetHostContent();
|
||||||
if (content != null)
|
if (content != null)
|
||||||
@@ -109,16 +111,11 @@ namespace TheXamlGuy.NotificationFlyout.Wpf.UI.Controls
|
|||||||
UpdateIcons();
|
UpdateIcons();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Flyout_Focused(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
_notificationFlyoutXamlHost.Activate();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void PrepareFlyoutHost()
|
private void PrepareFlyoutHost()
|
||||||
{
|
{
|
||||||
_notificationFlyoutXamlHost = new TransparentXamlHost<ContentControl>();
|
_notificationFlyoutXamlHost = new TransparentXamlHost<ContentControl>();
|
||||||
_notificationFlyoutXamlHost.Closed += OnNotificationFlyoutXamlHostClosed;
|
_notificationFlyoutXamlHost.Closed += OnNotificationFlyoutXamlHostClosed;
|
||||||
|
_notificationFlyoutXamlHost.Deactivated += OnNotificationFlyoutXamlHostDeactivated;
|
||||||
var taskbarState = _taskbarHelper.GetCurrentState();
|
var taskbarState = _taskbarHelper.GetCurrentState();
|
||||||
_notificationFlyoutXamlHost.Left = taskbarState.Screen.WorkingArea.Left;
|
_notificationFlyoutXamlHost.Left = taskbarState.Screen.WorkingArea.Left;
|
||||||
_notificationFlyoutXamlHost.Top = taskbarState.Screen.WorkingArea.Top;
|
_notificationFlyoutXamlHost.Top = taskbarState.Screen.WorkingArea.Top;
|
||||||
@@ -126,16 +123,26 @@ namespace TheXamlGuy.NotificationFlyout.Wpf.UI.Controls
|
|||||||
_notificationFlyoutXamlHost.Show();
|
_notificationFlyoutXamlHost.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnNotificationFlyoutXamlHostDeactivated(object sender, EventArgs args)
|
||||||
|
{
|
||||||
|
if (Flyout == null) return;
|
||||||
|
Flyout.Hide();
|
||||||
|
}
|
||||||
|
|
||||||
private void ShowFlyout()
|
private void ShowFlyout()
|
||||||
{
|
{
|
||||||
UpdateFlyoutPlacement();
|
if (Flyout == null) return;
|
||||||
|
|
||||||
|
UpdateFlyoutPlacement();
|
||||||
_notificationFlyoutXamlHost.Activate();
|
_notificationFlyoutXamlHost.Activate();
|
||||||
|
|
||||||
Flyout.Show();
|
Flyout.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateFlyoutPlacement()
|
private void UpdateFlyoutPlacement()
|
||||||
{
|
{
|
||||||
|
if (Flyout == null) return;
|
||||||
|
|
||||||
var taskbarState = _taskbarHelper.GetCurrentState();
|
var taskbarState = _taskbarHelper.GetCurrentState();
|
||||||
|
|
||||||
_notificationFlyoutXamlHost.Left = 0;
|
_notificationFlyoutXamlHost.Left = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user