我正在学习WPF。我试图通过使用Style.Trigger
对TextBlock
应用Background
和Foreground
。从我定义的Trigger
中,我可以注意到MouseOver
上的Foreground被更改,但不是Background
。你能帮忙吗?下面是我的XAML:WPF TextBlock BackGround未使用风格设置
<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>
感谢马克。我试过这样做,但没有效果。有什么明显的,我失踪了。 – 2013-02-27 03:08:25
@NainilPatel它正在处理您的示例代码。另外我做了一个编辑,看它现在是否有效。我刚刚发布了你的示例,我修改了这些修改。这确实有用。 – 2013-02-27 03:08:46
是的,这确实有效。非常感谢Mark。 – 2013-02-27 03:18:36