mirror of
https://github.com/AlexMacocian/WpfExtended.git
synced 2026-07-15 14:59:30 +00:00
Setup custom window chrome
This commit is contained in:
@@ -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">
|
||||
<Grid>
|
||||
<blazor:BlazorWebView
|
||||
x:Name="BlazorWebView"
|
||||
HostPage="{Binding ElementName=_this, Path=HostPage, Mode=OneWay}"
|
||||
Services="{Binding ElementName=_this, Path=Services, Mode=OneWay}">
|
||||
<blazor:BlazorWebView.RootComponents>
|
||||
<blazor:RootComponent x:Name="RootComponent" Selector="#app" />
|
||||
</blazor:BlazorWebView.RootComponents>
|
||||
</blazor:BlazorWebView>
|
||||
</Grid>
|
||||
<shell:WindowChrome.WindowChrome>
|
||||
<WindowChrome x:Name="WindowChrome" />
|
||||
</shell:WindowChrome.WindowChrome>
|
||||
<blazor:BlazorWebView
|
||||
x:Name="BlazorWebView"
|
||||
HostPage="{Binding ElementName=_this, Path=HostPage, Mode=OneWay}"
|
||||
Services="{Binding ElementName=_this, Path=Services, Mode=OneWay}">
|
||||
<blazor:BlazorWebView.RootComponents>
|
||||
<blazor:RootComponent x:Name="RootComponent" Selector="#app" />
|
||||
</blazor:BlazorWebView.RootComponents>
|
||||
</blazor:BlazorWebView>
|
||||
</Window>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFrameworks>net9.0-windows</TargetFrameworks>
|
||||
<UseWPF>true</UseWPF>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Version>0.7.15</Version>
|
||||
<Version>0.8.0</Version>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Description>
|
||||
Extension library for Blazor Hybrid running on Windows Presentation Platform.
|
||||
|
||||
Reference in New Issue
Block a user