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,40 +1,39 @@
using Microsoft.UI.Xaml; using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Hyperbar.Windows.UI; using Hyperbar.Windows.UI;
using Hyperbar.Windows.Interop;
using Windows.Foundation; using Windows.Foundation;
using WinUIEx;
using WindowStyle = Hyperbar.Windows.Interop.WindowStyle;
using System.Diagnostics;
namespace Hyperbar.Windows.Controls; namespace Hyperbar.Windows.Controls;
internal class DesktopFlyoutHost : Window internal class DesktopFlyoutHost : Window
{ {
private readonly DesktopFlyoutPresenter presenter; private readonly DesktopFlyoutPresenter presenter;
private bool loaded;
private DesktopFlyoutPlacement placement; private DesktopFlyoutPlacement placement;
private Popup? popup;
public DesktopFlyoutHost(DesktopFlyoutPresenter presenter) public DesktopFlyoutHost(DesktopFlyoutPresenter presenter)
{ {
Border root = new(); Border root = new();
root.Loaded += OnLoaded; root.Loaded += OnLoaded;
Content = root;
this.presenter = presenter; this.presenter = presenter;
presenter.SizeChanged += OnChildSizeChanged;
Content = root;
this.SetOpacity(0); this.SetOpacity(0);
this.SetStyle(WindowStyle.SysMenu | WindowStyle.Visible); this.SetStyle(WindowStyle.SysMenu | WindowStyle.Visible);
this.SetTopMost(true); this.SetTopMost(true);
this.SetIsShownInSwitchers(false); this.SetIsShownInSwitchers2(false);
} }
internal void UpdatePlacement(DesktopFlyoutPlacement placement) internal async void UpdatePlacement(DesktopFlyoutPlacement placement)
{ {
this.placement = placement; this.placement = placement;
// Not ready // Not ready
if (popup is null) if (!loaded)
{ {
return; return;
} }
@@ -44,10 +43,13 @@ internal class DesktopFlyoutHost : Window
double height = presenter.DesiredSize.Height; double height = presenter.DesiredSize.Height;
double width = presenter.DesiredSize.Width; double width = presenter.DesiredSize.Width;
Debug.WriteLine(height);
Debug.WriteLine(width);
switch (placement) switch (placement)
{ {
case DesktopFlyoutPlacement.Left: case DesktopFlyoutPlacement.Left:
this.Snap(WindowPlacement.Left, 0, 0); this.Snap(WindowPlacement.Left, height, width);
break; break;
case DesktopFlyoutPlacement.Top: case DesktopFlyoutPlacement.Top:
@@ -55,7 +57,7 @@ internal class DesktopFlyoutHost : Window
break; break;
case DesktopFlyoutPlacement.Right: case DesktopFlyoutPlacement.Right:
this.Snap(WindowPlacement.Right, 0, 0); this.Snap(WindowPlacement.Right, height, width);
break; break;
case DesktopFlyoutPlacement.Bottom: case DesktopFlyoutPlacement.Bottom:
@@ -72,23 +74,31 @@ internal class DesktopFlyoutHost : Window
presenter.TemplateSettings.SetValue(DesktopFlyoutPresenterTemplateSettings.NegativeHeightProperty, -height); presenter.TemplateSettings.SetValue(DesktopFlyoutPresenterTemplateSettings.NegativeHeightProperty, -height);
presenter.TemplateSettings.SetValue(DesktopFlyoutPresenterTemplateSettings.NegativeWidthProperty, -width); presenter.TemplateSettings.SetValue(DesktopFlyoutPresenterTemplateSettings.NegativeWidthProperty, -width);
await Task.Delay(TimeSpan.FromSeconds(4));
presenter.UpdatePlacementState(placement); presenter.UpdatePlacementState(placement);
} }
private void OnChildSizeChanged(object sender, private void OnChildSizeChanged(object sender,
SizeChangedEventArgs args) => UpdatePlacement(this.placement); SizeChangedEventArgs args) => UpdatePlacement(placement);
private void OnLoaded(object sender, private void OnLoaded(object sender,
RoutedEventArgs args) RoutedEventArgs args)
{ {
popup = new Popup SystemBackdrop = new TransparentTintBackdrop();
{ this.SetOpacity(255);
Child = presenter,
XamlRoot = Content.XamlRoot,
ShouldConstrainToRootBounds = false,
IsOpen = true,
};
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); UpdatePlacement(placement);
} }
} }
@@ -25,10 +25,10 @@
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="controls:DesktopFlyoutPresenter"> <ControlTemplate TargetType="controls:DesktopFlyoutPresenter">
<Border x:Name="Container"> <Border x:Name="Container" Background="Transparent">
<Border <Border
x:Name="BackgroundElement" x:Name="BackgroundElement"
Height="48" MinHeight="48"
MinWidth="40" MinWidth="40"
Margin="16" Margin="16"
Background="{TemplateBinding Background}" Background="{TemplateBinding Background}"
@@ -37,11 +37,6 @@
BorderThickness="{TemplateBinding BorderThickness}" BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}" CornerRadius="{TemplateBinding CornerRadius}"
FlowDirection="{TemplateBinding FlowDirection}"> FlowDirection="{TemplateBinding FlowDirection}">
<Border.Transitions>
<TransitionCollection>
<EntranceThemeTransition x:Name="EntranceThemeTransition" FromVerticalOffset="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.NegativeHeight}" />
</TransitionCollection>
</Border.Transitions>
<ContentControl <ContentControl
Height="40" Height="40"
Margin="4" Margin="4"
@@ -55,28 +50,16 @@
<VisualStateGroup x:Name="PlacementStates"> <VisualStateGroup x:Name="PlacementStates">
<VisualState x:Name="DefaultPlacement" /> <VisualState x:Name="DefaultPlacement" />
<VisualState x:Name="BottomPlacement"> <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>
<VisualState x:Name="TopPlacement"> <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>
<VisualState x:Name="LeftPlacement"> <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>
<VisualState x:Name="RightPlacement"> <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> </VisualState>
</VisualStateGroup> </VisualStateGroup>
</VisualStateManager.VisualStateGroups> </VisualStateManager.VisualStateGroups>
@@ -11,6 +11,8 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.231202003-experimental1" /> <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.231202003-experimental1" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.25936-preview" /> <PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.25936-preview" />
<PackageReference Include="WinUIEx" Version="2.3.3" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Hyperbar.Windows.Interop\Hyperbar.Windows.Interop.csproj" /> <ProjectReference Include="..\Hyperbar.Windows.Interop\Hyperbar.Windows.Interop.csproj" />
@@ -4,6 +4,7 @@ using Windows.Win32.UI.KeyboardAndMouseInput;
namespace Hyperbar.Windows.Interop; namespace Hyperbar.Windows.Interop;
public class VirtualKeyboard : public class VirtualKeyboard :
IVirtualKeyboard IVirtualKeyboard
{ {
@@ -10,7 +10,7 @@ public static class WindowExtensions
public static IntPtr GetHandle(this Window window) => public static IntPtr GetHandle(this Window window) =>
window is not null ? WindowNative.GetWindowHandle(window) : default; window is not null ? WindowNative.GetWindowHandle(window) : default;
public static void SetIsShownInSwitchers(this Window window, public static void SetIsShownInSwitchers2(this Window window,
bool value) => window.AppWindow.IsShownInSwitchers = value; bool value) => window.AppWindow.IsShownInSwitchers = value;
public static void SetOpacity(this Window window, public static void SetOpacity(this Window window,
+1 -2
View File
@@ -31,8 +31,7 @@
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.231202003-experimental1" /> <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.231202003-experimental1" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.25936-preview" /> <PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.25936-preview" />
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" /> <PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" /> <Manifest Include="$(ApplicationManifest)" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'"> <ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<ProjectCapability Include="Msix" /> <ProjectCapability Include="Msix" />
@@ -208,7 +208,7 @@ public partial class ObservableCollectionViewModel<TItem> :
public ValueTask Handle(Removed<TItem> notification, public ValueTask Handle(Removed<TItem> notification,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
foreach (TItem item in this) foreach (TItem item in this.ToList())
{ {
if (notification.Value is not null) if (notification.Value is not null)
{ {