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>
@@ -11,6 +11,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.231202003-experimental1" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.25936-preview" />
<PackageReference Include="WinUIEx" Version="2.3.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Hyperbar.Windows.Interop\Hyperbar.Windows.Interop.csproj" />
@@ -4,6 +4,7 @@ using Windows.Win32.UI.KeyboardAndMouseInput;
namespace Hyperbar.Windows.Interop;
public class VirtualKeyboard :
IVirtualKeyboard
{
@@ -10,7 +10,7 @@ public static class WindowExtensions
public static IntPtr GetHandle(this Window window) =>
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;
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.WindowsAppSDK" Version="1.5.231202003-experimental1" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.25936-preview" />
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" />
<Manifest Include="$(ApplicationManifest)" />
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" /> <Manifest Include="$(ApplicationManifest)" />
</ItemGroup>
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<ProjectCapability Include="Msix" />
@@ -38,7 +38,7 @@ public class ConfigurationReader<TConfiguration>(IConfigurationSource<TConfigura
{
byte[] jsonContent = File.ReadAllBytes(source.Path);
using JsonDocument jsonDocument = JsonDocument.Parse(jsonContent);
using JsonDocument jsonDocument = JsonDocument.Parse(jsonContent);
if (jsonDocument.RootElement.TryGetProperty(source.Section, out JsonElement sectionValue))
{
value = JsonSerializer.Deserialize<TConfiguration>(sectionValue.ToString(), serializerOptions ?? defaultSerializerOptions());
@@ -208,7 +208,7 @@ public partial class ObservableCollectionViewModel<TItem> :
public ValueTask Handle(Removed<TItem> notification,
CancellationToken cancellationToken)
{
foreach (TItem item in this)
foreach (TItem item in this.ToList())
{
if (notification.Value is not null)
{