我正在学习 WPF。我试图申请Background
和Foreground
使用TextBlock
. Style.Trigger
根据我的定义Trigger
,我可以注意到 Foreground 正在更改MouseOver
,但不是Background
。你能帮忙吗?下面是我的 XAML:
<Window x:Class="WpfApplication1.ApplyingStyle"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ApplyingStyle"
Height="300"
Width="300">
<Window.Resources>
<Style x:Key="myStyle">
<Setter Property="Control.Background"
Value="Red" />
<Setter Property="Control.FontFamily"
Value="Times New Roman" />
<Setter Property="Control.FontSize"
Value="25" />
<Style.Triggers>
<Trigger Property="Control.IsMouseOver"
Value="True">
<Setter Property="Control.Foreground"
Value="HotPink" />
<Setter Property="Control.Background"
Value="Blue" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Name="myTextBlock"
Grid.Row="1"
Grid.Column="0"
Style="{StaticResource myStyle}">Hello</TextBlock>
</Grid>
</Window>