我有这个默认前景颜色为白色的文本块
<TextBlock Text="First Cmd" Grid.Row="0" TextAlignment="Center" Margin="4" TextWrapping="Wrap" Foreground="White" Style="{DynamicResource ABC}">
<TextBlock.InputBindings>
<MouseBinding Command="{Binding AAA}" MouseAction="LeftClick" />
</TextBlock.InputBindings>
</TextBlock>当鼠标在文本块上时,基础颜色必须更改为黑色,但是这个样式的不能工作。为什么?
<Style x:Key="ABC" TargetType="{x:Type TextBlock}">
<Style.Triggers>
<Trigger Property ="IsMouseOver" Value="True">
<Setter Property= "Foreground" Value="Black">
</Trigger>
</Style.Triggers>
</Style>发布于 2015-10-20 14:38:22
您在本地为Foreground设置了TextBlock,因此Trigger设置器不能覆盖该设置。您需要使用样式设置器来设置初始前台:
<Style x:Key="ABC" TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="White"/>
<Style.Triggers>
<Trigger Property ="IsMouseOver" Value="True">
<Setter Property= "Foreground" Value="Black">
</Trigger>
</Style.Triggers>
</Style>Foreground="White"应该从<TextBlock ...中删除。
了解有关依赖属性值优先的更多信息。
https://stackoverflow.com/questions/33239557
复制相似问题