Allow placement to be updated at run time
This commit is contained in:
+22
-12
@@ -30,7 +30,7 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls
|
||||
public static readonly DependencyProperty PlacementProperty =
|
||||
DependencyProperty.Register(nameof(Placement),
|
||||
typeof(NotificationFlyoutPlacement), typeof(NotificationFlyout),
|
||||
new PropertyMetadata(NotificationFlyoutPlacement.Auto));
|
||||
new PropertyMetadata(NotificationFlyoutPlacement.Auto, OnPlacementPropertyChanged));
|
||||
|
||||
public static readonly DependencyProperty TemplateSettingsProperty =
|
||||
DependencyProperty.Register(nameof(TemplateSettings),
|
||||
@@ -59,10 +59,13 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls
|
||||
|
||||
public event EventHandler<object> Opened;
|
||||
|
||||
internal event EventHandler IconSourceChanged;
|
||||
internal event EventHandler IconSourcePropertyChanged;
|
||||
|
||||
internal event EventHandler InteractedWith;
|
||||
|
||||
internal event EventHandler PlacementPropertyChanged;
|
||||
|
||||
|
||||
public ImageSource IconSource
|
||||
{
|
||||
get => (ImageSource)GetValue(IconSourceProperty);
|
||||
@@ -121,6 +124,14 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls
|
||||
|
||||
internal static void SetApplication(INotificationFlyoutApplication application) => _applicationInstance = application;
|
||||
|
||||
internal void Close(bool shouldRespectIsLightDismissEnbabled)
|
||||
{
|
||||
if (!shouldRespectIsLightDismissEnbabled || IsLightDismissEnabled)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
internal void SetPlacement(double horizontalOffset, double verticalOffset, double workingAreaHeight, double workingAreaWidth, NotificationFlyoutTaskbarPlacement flyoutTaskbarPlacement)
|
||||
{
|
||||
if (_popup == null)
|
||||
@@ -213,15 +224,6 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls
|
||||
ShowMode = FlyoutShowMode.Standard
|
||||
});
|
||||
}
|
||||
|
||||
internal void Close(bool shouldRespectIsLightDismissEnbabled)
|
||||
{
|
||||
if (!shouldRespectIsLightDismissEnbabled || IsLightDismissEnabled)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
internal void UpdateTheme(bool isColorPrevalence) => VisualStateManager.GoToState(this, isColorPrevalence ? "ColorPrevalenceTheme" : "DefaultTheme", true);
|
||||
|
||||
protected override void OnApplyTemplate()
|
||||
@@ -259,9 +261,17 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls
|
||||
sender?.OnIconPropertyChanged();
|
||||
}
|
||||
|
||||
private static void OnPlacementPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
var sender = dependencyObject as NotificationFlyout;
|
||||
sender?.OnPlacementPropertyChanged();
|
||||
}
|
||||
|
||||
private void OnGotFocus(object sender, RoutedEventArgs args) => InteractedWith?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
private void OnIconPropertyChanged() => IconSourceChanged?.Invoke(this, EventArgs.Empty);
|
||||
private void OnIconPropertyChanged() => IconSourcePropertyChanged?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
private void OnPlacementPropertyChanged() => PlacementPropertyChanged?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
private void OnPointerPressed(object sender, PointerRoutedEventArgs args) => InteractedWith?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
|
||||
+10
-7
@@ -49,8 +49,6 @@ namespace TheXamlGuy.NotificationFlyout.Wpf.UI.Controls
|
||||
set => SetValue(FlyoutProperty, value);
|
||||
}
|
||||
|
||||
public void Exit() => _notificationFlyoutXamlHost.Close();
|
||||
|
||||
public void CloseFlyout(bool shouldRespectIsLightDismissEnbabled)
|
||||
{
|
||||
if (Flyout == null) return;
|
||||
@@ -59,6 +57,7 @@ namespace TheXamlGuy.NotificationFlyout.Wpf.UI.Controls
|
||||
|
||||
public void CloseFlyout() => CloseFlyout(false);
|
||||
|
||||
public void Exit() => _notificationFlyoutXamlHost.Close();
|
||||
public void OpenAsWindow<TUIElement>() where TUIElement : Windows.UI.Xaml.UIElement
|
||||
{
|
||||
var window = new XamlHost<TUIElement>();
|
||||
@@ -80,6 +79,12 @@ namespace TheXamlGuy.NotificationFlyout.Wpf.UI.Controls
|
||||
sender?.OnFlyoutPropertyChanged();
|
||||
}
|
||||
|
||||
private void OnFlyoutIconSourcePropertyChanged(object sender, EventArgs args) => UpdateIcons();
|
||||
|
||||
private void OnFlyoutInteractedWith(object sender, EventArgs args) => _notificationFlyoutXamlHost.Activate();
|
||||
|
||||
private void OnFlyoutPlacementPropertyChanged(object sender, EventArgs args) => UpdateFlyoutPlacement();
|
||||
|
||||
private void OnFlyoutPropertyChanged() => PrepareFlyout();
|
||||
|
||||
private void OnIconInvoked(object sender, NotificationIconInvokedEventArgs args)
|
||||
@@ -95,10 +100,6 @@ namespace TheXamlGuy.NotificationFlyout.Wpf.UI.Controls
|
||||
}
|
||||
}
|
||||
|
||||
private void OnFlyoutIconSourceChanged(object sender, EventArgs args) => UpdateIcons();
|
||||
|
||||
private void OnFlyoutInteractedWith(object sender, EventArgs args) => _notificationFlyoutXamlHost.Activate();
|
||||
|
||||
private void OnNotificationFlyoutXamlHostClosed(object sender, EventArgs args) => _notificationIconHelper?.Dispose();
|
||||
|
||||
private void OnNotificationFlyoutXamlHostDeactivated(object sender, EventArgs args) => CloseFlyout(true);
|
||||
@@ -114,7 +115,8 @@ namespace TheXamlGuy.NotificationFlyout.Wpf.UI.Controls
|
||||
private void PrepareFlyout()
|
||||
{
|
||||
if (Flyout == null) return;
|
||||
Flyout.IconSourceChanged += OnFlyoutIconSourceChanged;
|
||||
Flyout.IconSourcePropertyChanged += OnFlyoutIconSourcePropertyChanged;
|
||||
Flyout.PlacementPropertyChanged += OnFlyoutPlacementPropertyChanged;
|
||||
Flyout.InteractedWith += OnFlyoutInteractedWith;
|
||||
|
||||
var content = _notificationFlyoutXamlHost.GetHostContent();
|
||||
@@ -131,6 +133,7 @@ namespace TheXamlGuy.NotificationFlyout.Wpf.UI.Controls
|
||||
_notificationFlyoutXamlHost = new TransparentXamlHost<ContentControl>();
|
||||
_notificationFlyoutXamlHost.Closed += OnNotificationFlyoutXamlHostClosed;
|
||||
_notificationFlyoutXamlHost.Deactivated += OnNotificationFlyoutXamlHostDeactivated;
|
||||
|
||||
var taskbarState = _taskbarHelper.GetCurrentState();
|
||||
_notificationFlyoutXamlHost.Left = taskbarState.Screen.WorkingArea.Left;
|
||||
_notificationFlyoutXamlHost.Top = taskbarState.Screen.WorkingArea.Top;
|
||||
|
||||
Reference in New Issue
Block a user