Ash*_*Ash 39 wpf xaml text styles
如何在样式定义中包含文本装饰,如下划线,删除线等:
<Style x:Key="UnderlinedLabel">
<Setter Property="Control.FontFamily" Value="Trebuchet MS" />
<Setter Property="Control.FontSize" Value="14" />
<!-- Next line fails -->
<Setter Property="Control.TextDecorations" Value="Underline" />
</Style>
Run Code Online (Sandbox Code Playgroud)
我熟悉使用以下XAML来强调文本:
<TextBlock>
<Underline>
Underlined text
</Underline>
</TextBlock>
Run Code Online (Sandbox Code Playgroud)
然而文本修饰只是另一种风格,我希望能够像FontWeight,FontSize等一样明确地定义它.
[更新]
我正在将此样式应用于Label控件.这是我的主要问题.您似乎无法在Label中为文本加下划线.更改为TextBlock(感谢gix),一切都很好.
gix*_*gix 58
下划线文本可以使用<Underline>...</Underline>或TextDecorations设置为属性来完成Underline.您可以在样式定义中包含后者:
<Style x:Key="Underlined">
<Setter Property="TextBlock.TextDecorations" Value="Underline" />
</Style>
<TextBlock Style="{StaticResource Underlined}">
Foo
</TextBlock>
Run Code Online (Sandbox Code Playgroud)