WPF Add Border to Text Block

Is it possible to add a border to a text block. I need it to be added to the setter property below the code:

<Style x:Key="notCalled" TargetType="{x:Type TextBlock}"> <Setter Property="Margin" Value="2,2,2,2" /> <Setter Property="Background" Value="Transparent" /> </Style> 
+45
wpf
Oct. 19 '10 at 16:28
source share
2 answers

No, you need to wrap your TextBlock in a borderline. Example:

 <Border BorderThickness="1" BorderBrush="Black"> <TextBlock ... /> </Border> 

Of course, you can set these properties ( BorderThickness , BorderBrush ) through the styles:

 <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> 
+86
Oct 19 '10 at 16:32
source share

TextBlock does not actually inherit from Control, so it does not have properties that you usually associate with a control. Your best bet to add style border is to replace TextBlock with shortcut

See this link to learn more about the differences between TextBlock and other controls.

+16
Oct 19 '10 at 16:35
source share



All Articles