Popup had a fake invisible padding around it... however it seems we can now use the window now anyway

This commit is contained in:
TheXamlGuy
2024-01-16 08:15:57 +00:00
parent 5b0e09c6c1
commit 99855e77b9
8 changed files with 43 additions and 48 deletions
@@ -1,53 +1,55 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Hyperbar.Windows.UI;
using Hyperbar.Windows.Interop;
using Windows.Foundation;
using WinUIEx;
using WindowStyle = Hyperbar.Windows.Interop.WindowStyle;
using System.Diagnostics;
namespace Hyperbar.Windows.Controls;
internal class DesktopFlyoutHost : Window
{
private readonly DesktopFlyoutPresenter presenter;
private bool loaded;
private DesktopFlyoutPlacement placement;
private Popup? popup;
public DesktopFlyoutHost(DesktopFlyoutPresenter presenter)
{
Border root = new();
root.Loaded += OnLoaded;
Content = root;
this.presenter = presenter;
presenter.SizeChanged += OnChildSizeChanged;
Content = root;
this.SetOpacity(0);
this.SetStyle(WindowStyle.SysMenu | WindowStyle.Visible);
this.SetTopMost(true);
this.SetIsShownInSwitchers(false);
this.SetIsShownInSwitchers2(false);
}
internal void UpdatePlacement(DesktopFlyoutPlacement placement)
internal async void UpdatePlacement(DesktopFlyoutPlacement placement)
{
this.placement = placement;
// Not ready
if (popup is null)
if (!loaded)
{
return;
}
presenter.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
double height = presenter.DesiredSize.Height;
double width = presenter.DesiredSize.Width;
Debug.WriteLine(height);
Debug.WriteLine(width);
switch (placement)
{
case DesktopFlyoutPlacement.Left:
this.Snap(WindowPlacement.Left, 0, 0);
this.Snap(WindowPlacement.Left, height, width);
break;
case DesktopFlyoutPlacement.Top:
@@ -55,7 +57,7 @@ internal class DesktopFlyoutHost : Window
break;
case DesktopFlyoutPlacement.Right:
this.Snap(WindowPlacement.Right, 0, 0);
this.Snap(WindowPlacement.Right, height, width);
break;
case DesktopFlyoutPlacement.Bottom:
@@ -72,23 +74,31 @@ internal class DesktopFlyoutHost : Window
presenter.TemplateSettings.SetValue(DesktopFlyoutPresenterTemplateSettings.NegativeHeightProperty, -height);
presenter.TemplateSettings.SetValue(DesktopFlyoutPresenterTemplateSettings.NegativeWidthProperty, -width);
await Task.Delay(TimeSpan.FromSeconds(4));
presenter.UpdatePlacementState(placement);
}
private void OnChildSizeChanged(object sender,
SizeChangedEventArgs args) => UpdatePlacement(this.placement);
SizeChangedEventArgs args) => UpdatePlacement(placement);
private void OnLoaded(object sender,
RoutedEventArgs args)
{
popup = new Popup
{
Child = presenter,
XamlRoot = Content.XamlRoot,
ShouldConstrainToRootBounds = false,
IsOpen = true,
};
SystemBackdrop = new TransparentTintBackdrop();
this.SetOpacity(255);
if (Content is Border border)
{
border.Child = presenter;
double height = presenter.DesiredSize.Height;
double width = presenter.DesiredSize.Width;
presenter.SizeChanged += OnChildSizeChanged;
}
loaded = true;
UpdatePlacement(placement);
}
}
@@ -25,10 +25,10 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:DesktopFlyoutPresenter">
<Border x:Name="Container">
<Border x:Name="Container" Background="Transparent">
<Border
x:Name="BackgroundElement"
Height="48"
MinHeight="48"
MinWidth="40"
Margin="16"
Background="{TemplateBinding Background}"
@@ -37,11 +37,6 @@
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}"
FlowDirection="{TemplateBinding FlowDirection}">
<Border.Transitions>
<TransitionCollection>
<EntranceThemeTransition x:Name="EntranceThemeTransition" FromVerticalOffset="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.NegativeHeight}" />
</TransitionCollection>
</Border.Transitions>
<ContentControl
Height="40"
Margin="4"
@@ -55,28 +50,16 @@
<VisualStateGroup x:Name="PlacementStates">
<VisualState x:Name="DefaultPlacement" />
<VisualState x:Name="BottomPlacement">
<VisualState.Setters>
<Setter Target="EntranceThemeTransition.FromHorizontalOffset" Value="0" />
<Setter Target="EntranceThemeTransition.FromVerticalOffset" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.Height}" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="TopPlacement">
<VisualState.Setters>
<Setter Target="EntranceThemeTransition.FromHorizontalOffset" Value="0" />
<Setter Target="EntranceThemeTransition.FromVerticalOffset" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.NegativeHeight}" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="LeftPlacement">
<VisualState.Setters>
<Setter Target="EntranceThemeTransition.FromHorizontalOffset" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.NegativeWidth}" />
<Setter Target="EntranceThemeTransition.FromVerticalOffset" Value="0" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="RightPlacement">
<VisualState.Setters>
<Setter Target="EntranceThemeTransition.FromHorizontalOffset" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.Width}" />
<Setter Target="EntranceThemeTransition.FromVerticalOffset" Value="0" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>