写一个WPFTrigger触发器示例
时间: 2024-05-16 11:08:36 浏览: 272
以下是一个WPF Trigger触发器的示例,它会在鼠标悬停在Button上时改变Button的背景颜色:
```xaml
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Button Content="Hover over me!" Width="100" Height="50">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="Green"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
</Grid>
</Window>
```
当鼠标悬停在Button上时,Button的背景颜色会从绿色变为红色。
阅读全文