我想在窗口标题栏上进行关闭、最小化和最大化按钮的自定义。一些程序中,标题栏是不同的,但我不想改变整个标题栏,只想改变按钮。有人可以帮忙吗?
<Style x:Key="MyCustomWindowStyle" TargetType="{x:Type Window}">
<Setter Property="WindowStyle" Value="None"/>
<Setter Property="AllowsTransparency" Value="True"/>
<Setter Property="Background" Value="White"/>
<Setter Property="BorderBrush" Value="Blue"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
<Grid Background="{TemplateBinding Background}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<!-- this displays the window title -->
<TextBlock TextAlignment="Center"
Text="{TemplateBinding Title}"/>
<StackPanel Grid.Column="1"
Orientation="Horizontal"
HorizontalAlignment="Stretch"
VerticalAlignment="Center">
<!-- the minimize button, using your own style -->
<Button Style="{StaticResource MyMinimizeButtonStyle}"
Width="20"
Height="20" />
<!-- the close button, using your own style -->
<Button Style="{StaticResource MyCloseButtonStyle}"
Width="20"
Height="20" />
</StackPanel>
<!-- this displays the actual window content -->
<ContentPresenter Grid.Row="1"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
您可以使用WindowChrome自定义窗口样式:https://github.com/DinoChan/WindowDemo
此样式不使用SystemParameters2类,因为它在.net 4.5中不存在。