本文介绍了如何使标签文本下划线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在WPF中制作Label
文本Underline
?我被困住了,找不到下划线的任何属性:
How can I make Label
text Underline
in WPF? I am stucked and could not find any property for underline:
<Label Name="lblUserName"
Content="Username"
FontSize="14" FontWeight="Medium" />
推荐答案
在Label
中否,因此请尝试以下操作:
In Label
no TextDecorations
, therefore try this:
<Label Width="100" Height="30">
<TextBlock TextDecorations="Underline">TestText</TextBlock>
</Label>
Edit: more universal solution
more universal solution
在这种情况下,因为使用Content属性只能设置一次,所以不能使用Label.Tag
代替Label.Content
:
In this case, instead of Label.Content
using Label.Tag
, because Content property can be set only once:
<Label Tag="TestContent"
Width="100"
Height="30"
HorizontalContentAlignment="Center"
Background="AliceBlue">
<TextBlock TextDecorations="Underline"
Text="{Binding Path=Tag,
RelativeSource={RelativeSource Mode=FindAncestor,
AncestorType={x:Type Label}}}" />
</Label>
这篇关于如何使标签文本下划线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!