Enabled flyout transition to work at each taskbar placement, bottom, top, left, right
This commit is contained in:
+42
-19
@@ -3,7 +3,9 @@ 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;
|
||||
|
||||
namespace NotificationFlyout.Wpf.UI.Controls
|
||||
@@ -18,7 +20,6 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
||||
private WindowsXamlHost _host;
|
||||
|
||||
private NotificationIconHelper _notificationIconHelper;
|
||||
private bool _taskbarChanged;
|
||||
private TaskbarHelper _taskbarHelper;
|
||||
|
||||
public NotificationFlyoutXamlHost()
|
||||
@@ -49,10 +50,12 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
||||
_notificationIconHelper.SetIcon(handle);
|
||||
}
|
||||
|
||||
private const double MaximumOffset = 80;
|
||||
|
||||
internal void ShowFlyout()
|
||||
{
|
||||
var notificationFlyoutPresenter = GetNotificationFlyoutPresenter();
|
||||
if (notificationFlyoutPresenter != null)
|
||||
var flyoutPresenter = GetNotificationFlyoutPresenter();
|
||||
if (flyoutPresenter != null)
|
||||
{
|
||||
var taskbarState = _taskbarHelper.GetCurrentState();
|
||||
var flyoutPlacement = taskbarState.Position switch
|
||||
@@ -65,15 +68,10 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
||||
};
|
||||
|
||||
Activate();
|
||||
notificationFlyoutPresenter.ShowFlyout(flyoutPlacement);
|
||||
flyoutPresenter.ShowFlyout(flyoutPlacement);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetFlyoutPlacement(FlyoutPlacementMode placementMode)
|
||||
{
|
||||
var notificationFlyoutPresenter = GetNotificationFlyoutPresenter();
|
||||
}
|
||||
|
||||
private static void OnFlyoutContentPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
|
||||
{
|
||||
var sender = dependencyObject as NotificationFlyoutXamlHost;
|
||||
@@ -87,10 +85,10 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
||||
|
||||
private void OnFlyoutContentPropertyChanged()
|
||||
{
|
||||
var flyoutContentControl = GetNotificationFlyoutPresenter();
|
||||
if (flyoutContentControl != null)
|
||||
var flyoutPresenter = GetNotificationFlyoutPresenter();
|
||||
if (flyoutPresenter != null)
|
||||
{
|
||||
flyoutContentControl.Content = FlyoutContent;
|
||||
flyoutPresenter.Content = FlyoutContent;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,8 +107,6 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
||||
|
||||
private void OnTaskbarChanged(object sender, EventArgs args)
|
||||
{
|
||||
_taskbarChanged = true;
|
||||
|
||||
var taskbarState = _taskbarHelper.GetCurrentState();
|
||||
Left = taskbarState.Screen.WorkingArea.Left;
|
||||
Top = taskbarState.Screen.WorkingArea.Top;
|
||||
@@ -125,6 +121,7 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
||||
WindowStyle = WindowStyle.None;
|
||||
ResizeMode = ResizeMode.NoResize;
|
||||
AllowsTransparency = true;
|
||||
Background = new SolidColorBrush(Colors.Transparent);
|
||||
Height = 0;
|
||||
Width = 0;
|
||||
}
|
||||
@@ -156,6 +153,7 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
||||
|
||||
private void UpdateWindow()
|
||||
{
|
||||
var flyoutPresenter = GetNotificationFlyoutPresenter();
|
||||
var taskbarState = _taskbarHelper.GetCurrentState();
|
||||
|
||||
var screen = Screen.FromHandle(this.GetHandle());
|
||||
@@ -164,25 +162,50 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
||||
var windowWidth = DesiredSize.Width * this.DpiX();
|
||||
var windowHeight = DesiredSize.Height * this.DpiY();
|
||||
|
||||
double top;
|
||||
double left;
|
||||
double height;
|
||||
double width;
|
||||
double verticalOffset = 0;
|
||||
double horizontalOffset = 0;
|
||||
|
||||
var taskbarRect = taskbarState.Rect;
|
||||
var flyoutPlacement = FlyoutPlacementMode.Auto;
|
||||
switch (taskbarState.Position)
|
||||
{
|
||||
case TaskbarPosition.Left:
|
||||
this.SetWindowPosition(taskbarRect.Bottom - windowHeight, taskbarRect.Right, windowHeight, windowWidth);
|
||||
top = taskbarRect.Bottom - windowHeight;
|
||||
left = taskbarRect.Right;
|
||||
height = windowHeight;
|
||||
width = windowWidth;
|
||||
horizontalOffset = -MaximumOffset;
|
||||
break;
|
||||
case TaskbarPosition.Top:
|
||||
this.SetWindowPosition(taskbarRect.Bottom, FlowDirection == FlowDirection.RightToLeft ? taskbarRect.Left : taskbarRect.Right - windowWidth, windowHeight, windowWidth);
|
||||
top = taskbarRect.Bottom;
|
||||
left = FlowDirection == FlowDirection.RightToLeft ? taskbarRect.Left : taskbarRect.Right - windowWidth;
|
||||
height = windowHeight;
|
||||
width = windowWidth;
|
||||
verticalOffset = -MaximumOffset;
|
||||
break;
|
||||
case TaskbarPosition.Right:
|
||||
this.SetWindowPosition(taskbarRect.Bottom - windowHeight, taskbarRect.Left - windowWidth, windowHeight, windowWidth);
|
||||
top = taskbarRect.Bottom - windowHeight;
|
||||
left = taskbarRect.Left - windowWidth;
|
||||
height = windowHeight;
|
||||
width = windowWidth;
|
||||
horizontalOffset = MaximumOffset;
|
||||
break;
|
||||
case TaskbarPosition.Bottom:
|
||||
this.SetWindowPosition(taskbarRect.Top - windowHeight, FlowDirection == FlowDirection.RightToLeft ? taskbarRect.Left : taskbarRect.Right - windowWidth, windowHeight, windowWidth);
|
||||
top = taskbarRect.Top - windowHeight;
|
||||
left = FlowDirection == FlowDirection.RightToLeft ? taskbarRect.Left : taskbarRect.Right - windowWidth;
|
||||
height = windowHeight;
|
||||
width = windowWidth;
|
||||
verticalOffset = MaximumOffset;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
this.SetWindowPosition(top, left, height, width);
|
||||
flyoutPresenter.SetOffset(verticalOffset, horizontalOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user