
WindowEx.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:IFToolsControls.Controls">
<!--
https://www.cnblogs.com/webenh/p/17001190.html
https://www.cnblogs.com/s0611163/p/9994529.html
https://www.cnblogs.com/walterlv/p/10236439.html
https://blog.youkuaiyun.com/qq_43562262/article/details/133244427
-->
<Style TargetType="{x:Type local:WindowEx}">
<Style.Resources>
<FontFamily x:Key="IconFont">pack://application:,,,/IFToolsControls;component/Assets/Fonts/#IFToolsControls</FontFamily>
<ControlTemplate x:Key="CloseButtonTemplate" TargetType="Button">
<Border
x:Name="border"
BorderBrush="{Binding TitleButtonBorderBrush, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:WindowEx}}}"
CornerRadius="0 0 5 0"
SnapsToDevicePixels="true">
<TextBlock
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontFamily="{StaticResource IconFont}"
Text="" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="border" Property="Background" Value="red" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="OnlyCloseButtonTemplate" TargetType="Button">
<Border
x:Name="border"
BorderBrush="{Binding TitleButtonBorderBrush, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:WindowEx}}}"
CornerRadius="0 0 5 5"
SnapsToDevicePixels="true">
<TextBlock
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontFamily="{StaticResource IconFont}"
Text="" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="border" Property="Background" Value="red" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Style.Resources>
<Setter Property="AllowsTransparency" Value="True" />
<Setter Property="WindowStyle" Value="None" />
<Setter Property="Title" Value="MainWindow" />
<Setter Property="MinHeight" Value="35" />
<Setter Property="MinWidth" Value="119" />
<Setter Property="Icon" Value="pack://application:,,,/IFToolsControls;component/Assets/Images/WindowDefaultIcon.png" />
<Setter Property="WindowChrome.WindowChrome">
<Setter.Value>
<WindowChrome
CaptionHeight="30"
CornerRadius="5"
GlassFrameThickness="0"
NonClientFrameEdges="None"
ResizeBorderThickness="2"
UseAeroCaptionButtons="False" />
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:WindowEx}">
<Border
x:Name="PART_RootBorder"
Background="{Binding TitleBackground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:WindowEx}}}"
CornerRadius="5">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<Image
x:Name="PART_IconImage"
Width="16"
Height="16"
Margin="10,0,2,0"
Source="{TemplateBinding Icon}"
WindowChrome.IsHitTestVisibleInChrome="True" />
<TextBlock
Grid.Column="1"
Margin="2,0,0,0"
VerticalAlignment="Center"
FontFamily="{TemplateBinding FontFamily}"
FontSize="{Binding TitleFontSize, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:WindowEx}}}"
Foreground="{Binding TitleForeground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:WindowEx}}}"
Text="{TemplateBinding Title}" />
<!-- Border用于遮盖Title -->
<Border
Grid.Column=