[WIP] Positioning of popup
This commit is contained in:
@@ -4,10 +4,7 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:controls="using:TheXamlGuy.NotificationFlyout.Uwp.UI.Controls"
|
xmlns:controls="using:TheXamlGuy.NotificationFlyout.Uwp.UI.Controls"
|
||||||
Placement="Right">
|
Placement="Right">
|
||||||
<Grid
|
<Grid Width="500" Height="500">
|
||||||
Width="1000"
|
|
||||||
Height="1000"
|
|
||||||
Background="Red">
|
|
||||||
<Button
|
<Button
|
||||||
HorizontalAlignment="Right"
|
HorizontalAlignment="Right"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
|
|||||||
+21
-9
@@ -5,7 +5,6 @@ using Windows.UI;
|
|||||||
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.Markup;
|
|
||||||
using Windows.UI.Xaml.Media;
|
using Windows.UI.Xaml.Media;
|
||||||
|
|
||||||
namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls
|
namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls
|
||||||
@@ -34,7 +33,9 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls
|
|||||||
|
|
||||||
private static INotificationFlyoutApplication _applicationInstance;
|
private static INotificationFlyoutApplication _applicationInstance;
|
||||||
|
|
||||||
|
private UIElement _child;
|
||||||
private Popup _popup;
|
private Popup _popup;
|
||||||
|
public NotificationFlyout() => DefaultStyleKey = typeof(NotificationFlyout);
|
||||||
|
|
||||||
public event EventHandler<object> Closed;
|
public event EventHandler<object> Closed;
|
||||||
|
|
||||||
@@ -93,8 +94,10 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls
|
|||||||
PreparePopup();
|
PreparePopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
var width = 100;
|
_child.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
|
||||||
var height = 100;
|
|
||||||
|
var width = _child.DesiredSize.Width;
|
||||||
|
var height = _child.DesiredSize.Height;
|
||||||
|
|
||||||
var desiredHorizontalOffset = horizontalOffset;
|
var desiredHorizontalOffset = horizontalOffset;
|
||||||
var desiredVerticalOffset = verticalOffset;
|
var desiredVerticalOffset = verticalOffset;
|
||||||
@@ -102,7 +105,7 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls
|
|||||||
switch (flyoutTaskbarPlacement)
|
switch (flyoutTaskbarPlacement)
|
||||||
{
|
{
|
||||||
case NotificationFlyoutTaskbarPlacement.Left:
|
case NotificationFlyoutTaskbarPlacement.Left:
|
||||||
desiredVerticalOffset = 0;
|
desiredVerticalOffset -= height;
|
||||||
break;
|
break;
|
||||||
case NotificationFlyoutTaskbarPlacement.Top:
|
case NotificationFlyoutTaskbarPlacement.Top:
|
||||||
desiredHorizontalOffset -= width;
|
desiredHorizontalOffset -= width;
|
||||||
@@ -119,6 +122,8 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls
|
|||||||
|
|
||||||
_popup.HorizontalOffset = desiredHorizontalOffset;
|
_popup.HorizontalOffset = desiredHorizontalOffset;
|
||||||
_popup.VerticalOffset = desiredVerticalOffset;
|
_popup.VerticalOffset = desiredVerticalOffset;
|
||||||
|
|
||||||
|
VisualStateManager.GoToState(this, flyoutTaskbarPlacement.ToString(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Show()
|
internal void Show()
|
||||||
@@ -128,9 +133,19 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls
|
|||||||
PreparePopup();
|
PreparePopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_popup.Child = _child;
|
||||||
_popup.IsOpen = true;
|
_popup.IsOpen = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnApplyTemplate()
|
||||||
|
{
|
||||||
|
if (GetTemplateChild("Container") is Border container)
|
||||||
|
{
|
||||||
|
_child = container.Child;
|
||||||
|
container.Child = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void OnContextMenuPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
|
private static void OnContextMenuPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
|
||||||
{
|
{
|
||||||
var sender = dependencyObject as NotificationFlyout;
|
var sender = dependencyObject as NotificationFlyout;
|
||||||
@@ -157,16 +172,13 @@ namespace TheXamlGuy.NotificationFlyout.Uwp.UI.Controls
|
|||||||
|
|
||||||
private void PreparePopup()
|
private void PreparePopup()
|
||||||
{
|
{
|
||||||
var f = new Grid { Background = new SolidColorBrush(Colors.Blue), Height = 100, Width = 100 };
|
|
||||||
f.Children.Add(new Button { Content = "hefrefsef2" });
|
|
||||||
|
|
||||||
_popup = new Popup
|
_popup = new Popup
|
||||||
{
|
{
|
||||||
XamlRoot = XamlRoot,
|
XamlRoot = XamlRoot,
|
||||||
ShouldConstrainToRootBounds = false,
|
ShouldConstrainToRootBounds = false,
|
||||||
|
IsLightDismissEnabled = true,
|
||||||
HorizontalOffset = -1,
|
HorizontalOffset = -1,
|
||||||
VerticalOffset = -1,
|
VerticalOffset = -1
|
||||||
Child = f
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+34
-34
@@ -35,39 +35,39 @@
|
|||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
<Setter.Value>
|
<Setter.Value>
|
||||||
<ControlTemplate TargetType="controls:NotificationFlyout">
|
<ControlTemplate TargetType="controls:NotificationFlyout">
|
||||||
<Grid
|
<Border x:Name="Container">
|
||||||
x:Name="Root"
|
<Grid>
|
||||||
Padding="{TemplateBinding Padding}"
|
<Border
|
||||||
Background="{TemplateBinding Background}"
|
Padding="{TemplateBinding Padding}"
|
||||||
BackgroundSizing="OuterBorderEdge"
|
Background="{TemplateBinding Background}"
|
||||||
BorderBrush="{TemplateBinding BorderBrush}"
|
BackgroundSizing="OuterBorderEdge"
|
||||||
BorderThickness="{TemplateBinding BorderThickness}"
|
BorderBrush="{TemplateBinding BorderBrush}"
|
||||||
CornerRadius="{TemplateBinding CornerRadius}">
|
BorderThickness="{TemplateBinding BorderThickness}"
|
||||||
<Grid.Transitions>
|
CornerRadius="{TemplateBinding CornerRadius}">
|
||||||
<TransitionCollection>
|
<Border.Transitions>
|
||||||
<EntranceThemeTransition
|
<TransitionCollection>
|
||||||
x:Name="EntranceThemeTransition"
|
<EntranceThemeTransition x:Name="EntranceThemeTransition" />
|
||||||
FromHorizontalOffset="0"
|
</TransitionCollection>
|
||||||
FromVerticalOffset="0" />
|
</Border.Transitions>
|
||||||
</TransitionCollection>
|
<ScrollViewer
|
||||||
</Grid.Transitions>
|
x:Name="ScrollViewer"
|
||||||
<ScrollViewer
|
AutomationProperties.AccessibilityView="Raw"
|
||||||
x:Name="ScrollViewer"
|
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
|
||||||
AutomationProperties.AccessibilityView="Raw"
|
HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
|
||||||
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
|
VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
|
||||||
HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
|
VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"
|
||||||
VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
|
ZoomMode="{TemplateBinding ScrollViewer.ZoomMode}">
|
||||||
VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"
|
<ContentControl
|
||||||
ZoomMode="{TemplateBinding ScrollViewer.ZoomMode}">
|
x:Name="ContentPresenter"
|
||||||
<ContentControl
|
Margin="{TemplateBinding Padding}"
|
||||||
x:Name="ContentPresenter"
|
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||||
Margin="{TemplateBinding Padding}"
|
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
Content="{TemplateBinding Content}"
|
||||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
ContentTemplate="{TemplateBinding ContentTemplate}"
|
||||||
Content="{TemplateBinding Content}"
|
ContentTransitions="{TemplateBinding ContentTransitions}" />
|
||||||
ContentTemplate="{TemplateBinding ContentTemplate}"
|
</ScrollViewer>
|
||||||
ContentTransitions="{TemplateBinding ContentTransitions}" />
|
</Border>
|
||||||
</ScrollViewer>
|
</Grid>
|
||||||
<VisualStateManager.VisualStateGroups>
|
<VisualStateManager.VisualStateGroups>
|
||||||
<VisualStateGroup x:Name="PlacementStates">
|
<VisualStateGroup x:Name="PlacementStates">
|
||||||
<VisualState x:Name="Bottom">
|
<VisualState x:Name="Bottom">
|
||||||
@@ -110,7 +110,7 @@
|
|||||||
</VisualState>
|
</VisualState>
|
||||||
</VisualStateGroup>
|
</VisualStateGroup>
|
||||||
</VisualStateManager.VisualStateGroups>
|
</VisualStateManager.VisualStateGroups>
|
||||||
</Grid>
|
</Border>
|
||||||
</ControlTemplate>
|
</ControlTemplate>
|
||||||
</Setter.Value>
|
</Setter.Value>
|
||||||
</Setter>
|
</Setter>
|
||||||
|
|||||||
+6
-3
@@ -36,6 +36,7 @@ namespace TheXamlGuy.NotificationFlyout.Wpf.UI.Controls
|
|||||||
_systemPersonalisationHelper.ThemeChanged += OnThemeChanged;
|
_systemPersonalisationHelper.ThemeChanged += OnThemeChanged;
|
||||||
|
|
||||||
PrepareFlyoutHost();
|
PrepareFlyoutHost();
|
||||||
|
|
||||||
WndProcListener.Current.Start();
|
WndProcListener.Current.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,13 +65,15 @@ namespace TheXamlGuy.NotificationFlyout.Wpf.UI.Controls
|
|||||||
content.Content = Flyout;
|
content.Content = Flyout;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateIcons();
|
SetIcons();
|
||||||
|
SetFlyoutPlacement();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnIconInvoked(object sender, NotificationIconInvokedEventArgs args)
|
private void OnIconInvoked(object sender, NotificationIconInvokedEventArgs args)
|
||||||
{
|
{
|
||||||
if (args.PointerButton == PointerButton.Left)
|
if (args.PointerButton == PointerButton.Left)
|
||||||
{
|
{
|
||||||
|
_notificationFlyoutXamlHost.Activate();
|
||||||
Flyout.Show();
|
Flyout.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +83,7 @@ namespace TheXamlGuy.NotificationFlyout.Wpf.UI.Controls
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void OnIconSourceChanged(object sender, EventArgs args) => UpdateIcons();
|
private void OnIconSourceChanged(object sender, EventArgs args) => SetIcons();
|
||||||
|
|
||||||
private void OnNotificationFlyoutXamlHostClosed(object sender, EventArgs args)
|
private void OnNotificationFlyoutXamlHostClosed(object sender, EventArgs args)
|
||||||
{
|
{
|
||||||
@@ -153,7 +156,7 @@ namespace TheXamlGuy.NotificationFlyout.Wpf.UI.Controls
|
|||||||
Flyout.SetPlacement(left, top, flyoutTaskBarPlacement);
|
Flyout.SetPlacement(left, top, flyoutTaskBarPlacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void UpdateIcons()
|
private async void SetIcons()
|
||||||
{
|
{
|
||||||
if (Flyout == null) return;
|
if (Flyout == null) return;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user