From 103ee09b0e1b11edc4ddb40508ae2d34c7b04368 Mon Sep 17 00:00:00 2001 From: Alex Macocian Date: Sat, 2 Aug 2025 00:33:26 +0200 Subject: [PATCH] Setup custom window chrome --- .../Launch/BlazorHostWindow.xaml | 22 ++++++++++--------- .../Launch/BlazorHostWindow.xaml.cs | 19 ++++++++++++++-- WpfExtended.Blazor/WpfExtended.Blazor.csproj | 2 +- WpfExtended/WpfExtended.csproj | 2 +- 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/WpfExtended.Blazor/Launch/BlazorHostWindow.xaml b/WpfExtended.Blazor/Launch/BlazorHostWindow.xaml index a44fc6c..a234b94 100644 --- a/WpfExtended.Blazor/Launch/BlazorHostWindow.xaml +++ b/WpfExtended.Blazor/Launch/BlazorHostWindow.xaml @@ -6,19 +6,21 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:WpfExtended.Blazor.Launch" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:shell="clr-namespace:System.Windows.Shell;assembly=PresentationFramework" x:Name="_this" Title="BlazorHostWindow" Width="800" Height="450" mc:Ignorable="d"> - - - - - - - + + + + + + + + diff --git a/WpfExtended.Blazor/Launch/BlazorHostWindow.xaml.cs b/WpfExtended.Blazor/Launch/BlazorHostWindow.xaml.cs index be05bb0..676d77a 100644 --- a/WpfExtended.Blazor/Launch/BlazorHostWindow.xaml.cs +++ b/WpfExtended.Blazor/Launch/BlazorHostWindow.xaml.cs @@ -33,8 +33,8 @@ public partial class BlazorHostWindow : Window set { this.SetValue(ShowTitleBarProperty, value); - this.WindowStyle = value ? WindowStyle.SingleBorderWindow : WindowStyle.None; - this.ResizeMode = value ? ResizeMode.CanResize : ResizeMode.NoResize; + this.WindowChrome.CaptionHeight = value ? SystemParameters.CaptionHeight : 0; + this.BlazorWebView.Margin = value ? new Thickness(0, SystemParameters.CaptionHeight, 0, 0) : new Thickness(0); } } @@ -64,4 +64,19 @@ public partial class BlazorHostWindow : Window this.HostPage = blazorLaunchProperties.HostPage; this.AppType = blazorLaunchProperties.AppType; } + + protected override void OnStateChanged(EventArgs e) + { + base.OnStateChanged(e); + var cornerRadius = Math.Max( + Math.Max(SystemParameters.WindowCornerRadius.TopLeft, SystemParameters.WindowCornerRadius.TopRight), + Math.Max(SystemParameters.WindowCornerRadius.BottomLeft, SystemParameters.WindowCornerRadius.BottomRight)); + this.WindowChrome.ResizeBorderThickness = this.WindowState is WindowState.Maximized ? new Thickness(0) : new Thickness(cornerRadius); + this.WindowChrome.CornerRadius = this.WindowState is WindowState.Maximized ? new CornerRadius(0) : SystemParameters.WindowCornerRadius; + this.BlazorWebView.Margin = this.WindowState is WindowState.Maximized + ? this.ShowTitleBar + ? new Thickness(cornerRadius, SystemParameters.CaptionHeight + cornerRadius, cornerRadius, cornerRadius) + : new Thickness(cornerRadius) + : new Thickness(0, this.ShowTitleBar ? SystemParameters.CaptionHeight : 0, 0, 0); + } } diff --git a/WpfExtended.Blazor/WpfExtended.Blazor.csproj b/WpfExtended.Blazor/WpfExtended.Blazor.csproj index e775172..5f7d1b6 100644 --- a/WpfExtended.Blazor/WpfExtended.Blazor.csproj +++ b/WpfExtended.Blazor/WpfExtended.Blazor.csproj @@ -4,7 +4,7 @@ net9.0-windows true true - 0.7.15 + 0.8.0 latest Extension library for Blazor Hybrid running on Windows Presentation Platform. diff --git a/WpfExtended/WpfExtended.csproj b/WpfExtended/WpfExtended.csproj index 402e7cc..f98b530 100644 --- a/WpfExtended/WpfExtended.csproj +++ b/WpfExtended/WpfExtended.csproj @@ -4,7 +4,7 @@ net9.0-windows true true - 0.7.15 + 0.8.0 latest Extension library for Windows Presentation Platform.