我有文本块,默认前景色为白色
Headers
当鼠标位于文本块上时,forground颜色必须以黑色更改,但此样式不起作用。为什么?
<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>
答案 0 :(得分:5)
您在本地为Foreground
设置了TextBlock
,因此Trigger
setter无法覆盖该<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 ...
应从"Anonymous Authentication."
删除。