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