I want my TextBlock to look disabled (grayed out) but when I set IsEnabled
property to false nothing happens, it stays black:
<TextBlock Text="test" IsEnabled="False" />
Why is that?
Also I tried to use Label
but it's size is bigger for some reason, so it will mess up all my layout.
Text block is the primary control for displaying read-only text in apps. You can use it to display single-line or multi-line text, inline hyperlinks, and text with formatting like bold, italic, or underlined.
TextBlock is not editable.
The TextBlock control provides flexible text support for UI scenarios that do not require more than one paragraph of text. It supports a number of properties that enable precise control of presentation, such as FontFamily, FontSize, FontWeight, TextEffects, and TextWrapping.
This would be the proper way to do it with a TextBlock i think:
<TextBlock Text="Lorem ipsum dolor sit"> <TextBlock.Style> <Style TargetType="{x:Type TextBlock}"> <Style.Triggers> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Foreground" Value="{StaticResource {x:Static SystemColors.GrayTextBrushKey}}"/> </Trigger> </Style.Triggers> </Style> </TextBlock.Style> </TextBlock>
I played a little and found out that half opacity is giving the same resultat as IsEnabled="False".
<TextBlock Text="test" Opacity="0.5" />
Advantage : it fits to every Foreground color.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With