WPF 为 TextBlock 添加边框 [英] WPF Add a Border to a TextBlock
本文介绍了WPF 为 TextBlock 添加边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以为文本块添加边框.我需要将它添加到下面代码的 setter 属性中:
Is it possible to add a border to a textblock. I need it to be added in the setter property below code:
<Style x:Key="notCalled" TargetType="{x:Type TextBlock}">
<Setter Property="Margin" Value="2,2,2,2" />
<Setter Property="Background" Value="Transparent" />
</Style>
推荐答案
不,您需要将 TextBlock 包裹在边框中.示例:
No, you need to wrap your TextBlock in a Border. Example:
<Border BorderThickness="1" BorderBrush="Black">
<TextBlock ... />
</Border>
当然,您也可以通过样式设置这些属性(BorderThickness
、BorderBrush
):
Of course, you can set these properties (BorderThickness
, BorderBrush
) through styles as well:
<Style x:Key="notCalledBorder" TargetType="{x:Type Border}">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderBrush" Value="Black" />
</Style>
<Border Style="{StaticResource notCalledBorder}">
<TextBlock ... />
</Border>
这篇关于WPF 为 TextBlock 添加边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文