47 lines
2.6 KiB
XML
47 lines
2.6 KiB
XML
<Window x:Class="_5_17._4改变属性触发器2.MainWindow"
|
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
|
mc:Ignorable="d"
|
|
Title="MainWindow" Height="450" Width="800">
|
|
<Window.Resources>
|
|
<ControlTemplate x:Key="ButtonControlTemplate" TargetType="{x:Type Button}">
|
|
<Border Name="Border" BorderBrush="Orange" BorderThickness="3" CornerRadius="2" Background="Red"
|
|
TextBlock.Foreground="White">
|
|
<Grid>
|
|
<!-- 获取焦点时周围自定义的边框 -->
|
|
<Rectangle Name="FocusCue" Visibility="Hidden" Stroke="Black" StrokeThickness="1"
|
|
StrokeDashArray="1 2" SnapsToDevicePixels="True" />
|
|
<ContentPresenter RecognizesAccessKey="True" Margin="{TemplateBinding Padding}" />
|
|
</Grid>
|
|
</Border>
|
|
|
|
<ControlTemplate.Triggers>
|
|
<Trigger Property="IsMouseOver" Value="True">
|
|
<Setter TargetName="Border" Property="Background" Value="DarkRed" />
|
|
</Trigger>
|
|
|
|
<Trigger Property="IsPressed" Value="True">
|
|
<Setter TargetName="Border" Property="Background" Value="Indigo" />
|
|
<Setter TargetName="Border" Property="BorderBrush" Value="DarkKhaki" />
|
|
</Trigger>
|
|
|
|
<Trigger Property="IsEnabled" Value="False">
|
|
<Setter TargetName="Border" Property="TextBlock.Background" Value="Gray" />
|
|
<Setter TargetName="Border" Property="Background" Value="MistyRose" />
|
|
</Trigger>
|
|
|
|
<Trigger Property="IsKeyboardFocused" Value="True">
|
|
<Setter TargetName="FocusCue" Property="Visibility" Value="Visible" />
|
|
</Trigger>
|
|
</ControlTemplate.Triggers>
|
|
</ControlTemplate>
|
|
</Window.Resources>
|
|
<StackPanel>
|
|
<Button Template="{StaticResource ButtonControlTemplate}" Margin="10" Padding="15 5">按钮</Button>
|
|
<Button Template="{StaticResource ButtonControlTemplate}" Margin="10" Padding="15 5" IsEnabled="False">禁用按钮</Button>
|
|
<Button Template="{StaticResource ButtonControlTemplate}" Margin="10" Padding="15 5">按钮</Button>
|
|
<Button Template="{StaticResource ButtonControlTemplate}" Margin="10" Padding="15 5">按钮</Button>
|
|
</StackPanel>
|
|
</Window> |