Poma Poma - 1 year ago 96
C# Question

How to disable TextBlock?

I want my TextBlock to look disabled (grayed out) but when I set

property to false nothing happens, it stays black:

<TextBlock Text="test" IsEnabled="False" />

Why is that?

Also I tried to use
but it's size is bigger for some reason, so it will mess up all my layout.

Answer Source

This would be the proper way to do it with a TextBlock i think:

<TextBlock Text="Lorem ipsum dolor sit">
        <Style TargetType="{x:Type TextBlock}">
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Foreground"
                            Value="{StaticResource {x:Static SystemColors.GrayTextBrushKey}}"/>