如何使用Setter属性在WPF中绘制下划线 [英] How to draw underline in wpf using Setter property
本文介绍了如何使用Setter属性在WPF中绘制下划线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写了一个触发器,如下所示:-
Hi,
I have written one trigger as below:-
<Trigger Property="IsLastActivated" Value="true">
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource LastActivatedOff}" x:Name="LastActivatedOff_BeginStoryboard" />
</Trigger.ExitActions>
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource LastActivatedOn}" x:Name="LastActivatedOn_BeginStoryboard" />
</Trigger.EnterActions>
<Setter Property="FontStyle" Value="Italic"/>
</Trigger>
现在,我想在触发动作发生时也画下划线.但是我不能使用下面的属性做同样的事情
now I want to draw underline as well when trigger action happen. But i am not able to do the same using below property
<Setter Property="TextBlock.TextDecorations" value="Underline">
如果您有任何想法,请告诉我.此触发器也将应用于TextBlock.
Kindly let me know if you have any idea. Also this trigger will be applied on TextBlock.
推荐答案
您好...只要记住将触发器放入样式中即可.只能在控件中直接定义EventTriggers.这应该可以工作:
Hi... just remember to put your trigger inside an style. Only EventTriggers can be defined directly in the control. This should work:
<textblock height="23">
HorizontalAlignment="Left"
Margin="154,102,0,0"
Name="textBlock1"
Text="TextBlock"
VerticalAlignment="Top">
<textblock.style>
<style targettype="TextBlock">
<style.triggers>
<trigger property="IsMouseOver">
Value="true">
<setter property="TextBlock.TextDecorations">
Value="Underline"/>
</setter></trigger>
</style.triggers>
</style>
</textblock.style>
</textblock>
这篇关于如何使用Setter属性在WPF中绘制下划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文