WPF 关闭按钮
<Window x:Class="TestCloseButton.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" SizeToContent="WidthAndHeight" WindowStyle="None" WindowStartupLocation="CenterScreen" ShowInTaskbar="False" ResizeMode="NoResize" Title="MenuManagementWindow" > <Window.Resources> <ResourceDictionary> <Style x:Key="TopRightCloseButtonStyle" TargetType="{x:Type ToggleButton}"> <Setter Property="FocusVisualStyle" Value="{x:Null}"/> <Setter Property="Focusable" Value="False"/> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ToggleButton}"> <Grid > <Rectangle Margin="0,0,0,0" x:Name="Rectangle" Fill="Transparent"> </Rectangle> <Border x:Name="border" Width="32" Height="16" BorderThickness="1" CornerRadius="0,0,5,0" BorderBrush="#BDBDBD" Background="#F2f2f2"> <Path x:Name="path" Fill="#FFababab" Stretch="Fill" HorizontalAlignment="Center" Margin="0" VerticalAlignment="Center" Width="8.708" Height="8.248" RenderTransformOrigin="0.5,0.5" Data="M0.26855466,2.2613707 L2.9487305,2.2613707 L4.3452148,4.6837339 L5.6987305,2.2613707 L8.3520508,2.2613707 L5.902832,6.0748472 L8.5830078,10.135394 L5.8491211,10.135394 L4.296875,7.6056089 L2.7392578,10.135394 L0.021484375,10.135394 L2.7392578,6.0318785 z"> <Path.RenderTransform> <TransformGroup> <ScaleTransform/> <SkewTransform/> <RotateTransform/> <TranslateTransform/> </TransformGroup> </Path.RenderTransform> </Path> </Border> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter Property="Background" TargetName="border" Value="#FFFFFF"> </Setter> </Trigger> <Trigger Property="IsPressed" Value="true"> <Setter Property="Background" TargetName="border"> <Setter.Value> <!-- PressedBrush is used for Pressed in Button, Radio Button, CheckBox --> <LinearGradientBrush EndPoint="0,1" StartPoint="0,0"> <GradientStop Color="#FFF" Offset="0.0"/> <GradientStop Color="#EEE" Offset="0.1"/> <GradientStop Color="#EEE" Offset="0.9"/> <GradientStop Color="#FFF" Offset="1.0"/> </LinearGradientBrush> </Setter.Value> </Setter> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <SolidColorBrush x:Key="MainWindowBorderBrush" Color="#6c6c6c"/> <LinearGradientBrush x:Key="TitleBackgroundBrush" EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#3a4d6b" Offset="0"/> <GradientStop Color="#364b70" Offset="1"/> </LinearGradientBrush> <LinearGradientBrush x:Key="AppBackgroundBrush" EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#5f5f5f" Offset="0"/> <GradientStop Color="#5b5b5b" Offset="1"/> </LinearGradientBrush> <LinearGradientBrush x:Key="TitleAeraBackgroundBrush" EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#cfcfcf" Offset="0"/> <GradientStop Color="#9c9c9c" Offset="1"/> </LinearGradientBrush> <LinearGradientBrush x:Key="TitleAeraBackgroundBrushReverse" EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#9c9c9c" Offset="0"/> <GradientStop Color="#cfcfcf" Offset="1"/> </LinearGradientBrush> </ResourceDictionary> </Window.Resources> <Grid x:Name="layoutRoot" Height="640" Width="800"> <Grid x:Name="gridMain" Background="{x:Null}" Margin="0,0,0,0" VerticalAlignment="Stretch"> <Grid.RowDefinitions> <RowDefinition Height="auto" ></RowDefinition> <RowDefinition Height="auto" ></RowDefinition> <RowDefinition Height="*"></RowDefinition> </Grid.RowDefinitions> <Border Grid.RowSpan="3" CornerRadius="4" BorderBrush="{StaticResource MainWindowBorderBrush}" BorderThickness="1" > </Border> <ToggleButton Height="16" Width="32" Grid.Row="1" x:Name="closeButton" Style="{DynamicResource TopRightCloseButtonStyle}" /> </Grid> </Grid> </Window>