5-WPFTemplates-And-CustomEl.../5-17.4改变属性触发器/MainWindow.xaml

28 lines
1.4 KiB
XML

<Window x:Class="_5_17._4改变属性触发器.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="BlueViolet"
TextBlock.Foreground="White">
<ContentPresenter RecognizesAccessKey="True" Margin="{TemplateBinding Padding}" />
</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="DarkKhaki" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Window.Resources>
<StackPanel>
<Button Template="{StaticResource ButtonControlTemplate}" Margin="15" Padding="15">按钮</Button>
</StackPanel>
</Window>