说明:本文主要是使用TextBlock控件以及鼠标聚焦后字体变蓝举例说明,也可以自行用其他的控件做其他的行为,具体效果如图所示:
具体实现代码如下:
<Style x:Key="TextBlockCommon" TargetType="{x:Type TextBlock}">
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="TextWrapping" Value="Wrap" />
<Setter Property="Foreground" Value="Yellow"/>
<Style.Triggers>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<!-- 当文本框获得焦点时,将字体颜色更改为蓝色 -->
<Setter Property="Foreground" Value="Blue"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<!-- 当鼠标悬停在文本框上时,将字体颜色更改为蓝色 -->
<Setter Property="Foreground" Value="Blue"/>
</Trigger>
</Style.Triggers>
</Style>
作者:freesheep720