diff --git a/Hyperbar.Windows.Controls/DesktopFlyout/DesktopFlyoutHost.cs b/Hyperbar.Windows.Controls/DesktopFlyout/DesktopFlyoutHost.cs index aa180e6..d2904f1 100644 --- a/Hyperbar.Windows.Controls/DesktopFlyout/DesktopFlyoutHost.cs +++ b/Hyperbar.Windows.Controls/DesktopFlyout/DesktopFlyoutHost.cs @@ -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); } } \ No newline at end of file diff --git a/Hyperbar.Windows.Controls/DesktopFlyout/DesktopFlyoutPresenter.xaml b/Hyperbar.Windows.Controls/DesktopFlyout/DesktopFlyoutPresenter.xaml index e6cc739..97b1ce7 100644 --- a/Hyperbar.Windows.Controls/DesktopFlyout/DesktopFlyoutPresenter.xaml +++ b/Hyperbar.Windows.Controls/DesktopFlyout/DesktopFlyoutPresenter.xaml @@ -25,10 +25,10 @@ - + - - - - - - - - - + - - - - + - - - - + - - - - + diff --git a/Hyperbar.Windows.Controls/Hyperbar.Windows.Controls.csproj b/Hyperbar.Windows.Controls/Hyperbar.Windows.Controls.csproj index adab486..ef10394 100644 --- a/Hyperbar.Windows.Controls/Hyperbar.Windows.Controls.csproj +++ b/Hyperbar.Windows.Controls/Hyperbar.Windows.Controls.csproj @@ -11,6 +11,8 @@ + + diff --git a/Hyperbar.Windows.Interop/VirtualKeyboard.cs b/Hyperbar.Windows.Interop/VirtualKeyboard.cs index 20e2f96..311da1d 100644 --- a/Hyperbar.Windows.Interop/VirtualKeyboard.cs +++ b/Hyperbar.Windows.Interop/VirtualKeyboard.cs @@ -4,6 +4,7 @@ using Windows.Win32.UI.KeyboardAndMouseInput; namespace Hyperbar.Windows.Interop; + public class VirtualKeyboard : IVirtualKeyboard { diff --git a/Hyperbar.Windows.UI/Extensions/WindowExtensions.cs b/Hyperbar.Windows.UI/Extensions/WindowExtensions.cs index f937ba8..38a299f 100644 --- a/Hyperbar.Windows.UI/Extensions/WindowExtensions.cs +++ b/Hyperbar.Windows.UI/Extensions/WindowExtensions.cs @@ -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, diff --git a/Hyperbar.Windows/Hyperbar.Windows.csproj b/Hyperbar.Windows/Hyperbar.Windows.csproj index 270c63a..ac508c9 100644 --- a/Hyperbar.Windows/Hyperbar.Windows.csproj +++ b/Hyperbar.Windows/Hyperbar.Windows.csproj @@ -31,8 +31,7 @@ - - + diff --git a/Hyperbar/Configuration/ConfigurationReader.cs b/Hyperbar/Configuration/ConfigurationReader.cs index eda91be..11bec35 100644 --- a/Hyperbar/Configuration/ConfigurationReader.cs +++ b/Hyperbar/Configuration/ConfigurationReader.cs @@ -38,7 +38,7 @@ public class ConfigurationReader(IConfigurationSource(sectionValue.ToString(), serializerOptions ?? defaultSerializerOptions()); diff --git a/Hyperbar/Views/ObservableCollectionViewModel.cs b/Hyperbar/Views/ObservableCollectionViewModel.cs index ed97c53..62aaa57 100644 --- a/Hyperbar/Views/ObservableCollectionViewModel.cs +++ b/Hyperbar/Views/ObservableCollectionViewModel.cs @@ -208,7 +208,7 @@ public partial class ObservableCollectionViewModel : public ValueTask Handle(Removed notification, CancellationToken cancellationToken) { - foreach (TItem item in this) + foreach (TItem item in this.ToList()) { if (notification.Value is not null) {