Added offset value to offset the popup position by 1px

This commit is contained in:
Daniel Clark
2021-02-27 14:18:32 +00:00
parent 5db230c83c
commit 8e334912b9
2 changed files with 25 additions and 3 deletions
@@ -5,6 +5,7 @@ using Windows.Foundation;
using Windows.UI.Xaml; using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives; using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Media;
namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls
@@ -21,6 +22,7 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls
typeof(ImageSource), typeof(NotificationFlyout), typeof(ImageSource), typeof(NotificationFlyout),
new PropertyMetadata(null)); new PropertyMetadata(null));
private const double OffsetValue = 1;
private static INotificationFlyoutApplication _applicationInstance; private static INotificationFlyoutApplication _applicationInstance;
private UIElement _child; private UIElement _child;
@@ -33,6 +35,7 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls
public event EventHandler<object> Opened; public event EventHandler<object> Opened;
internal event EventHandler IconSourceChanged; internal event EventHandler IconSourceChanged;
internal event EventHandler InteractedWith;
public ImageSource IconSource public ImageSource IconSource
{ {
@@ -68,10 +71,12 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls
switch (flyoutTaskbarPlacement) switch (flyoutTaskbarPlacement)
{ {
case NotificationFlyoutTaskbarPlacement.Left: case NotificationFlyoutTaskbarPlacement.Left:
desiredHorizontalOffset -= OffsetValue;
desiredVerticalOffset -= height; desiredVerticalOffset -= height;
break; break;
case NotificationFlyoutTaskbarPlacement.Top: case NotificationFlyoutTaskbarPlacement.Top:
desiredHorizontalOffset -= width; desiredHorizontalOffset -= width;
desiredVerticalOffset -= OffsetValue;
break; break;
case NotificationFlyoutTaskbarPlacement.Right: case NotificationFlyoutTaskbarPlacement.Right:
desiredHorizontalOffset -= width; desiredHorizontalOffset -= width;
@@ -117,7 +122,16 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls
_container = GetTemplateChild("Container") as Border; _container = GetTemplateChild("Container") as Border;
if (_container != null) if (_container != null)
{ {
if (_child != null)
{
_child.PointerPressed += OnPointerPressed;
_child.GotFocus -= OnGotFocus;
}
_child = _container.Child; _child = _container.Child;
_child.PointerPressed += OnPointerPressed;
_child.GotFocus += OnGotFocus;
_container.Child = null; _container.Child = null;
} }
@@ -137,8 +151,11 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls
sender?.OnIconPropertyChanged(); sender?.OnIconPropertyChanged();
} }
private void OnGotFocus(object sender, RoutedEventArgs args) => InteractedWith?.Invoke(this, EventArgs.Empty);
private void OnIconPropertyChanged() => IconSourceChanged?.Invoke(this, EventArgs.Empty); private void OnIconPropertyChanged() => IconSourceChanged?.Invoke(this, EventArgs.Empty);
private void OnPointerPressed(object sender, PointerRoutedEventArgs args) => InteractedWith?.Invoke(this, EventArgs.Empty);
private void OnPopupClosed(object sender, object args) => Opened?.Invoke(this, args); private void OnPopupClosed(object sender, object args) => Opened?.Invoke(this, args);
private void OnPopupOpened(object sender, object args) => Closed?.Invoke(this, args); private void OnPopupOpened(object sender, object args) => Closed?.Invoke(this, args);
@@ -149,9 +166,8 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls
{ {
XamlRoot = XamlRoot, XamlRoot = XamlRoot,
ShouldConstrainToRootBounds = false, ShouldConstrainToRootBounds = false,
IsLightDismissEnabled = true, HorizontalOffset = -OffsetValue,
HorizontalOffset = -1, VerticalOffset = -OffsetValue
VerticalOffset = -1
}; };
_popup.Opened += OnPopupOpened; _popup.Opened += OnPopupOpened;
@@ -98,6 +98,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; ;
var content = _notificationFlyoutXamlHost.GetHostContent(); var content = _notificationFlyoutXamlHost.GetHostContent();
if (content != null) if (content != null)
@@ -108,6 +109,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>();