Poma Poma - 1 month ago 12
C# Question

How to disable TextBlock?

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.

Answer

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>