How to disable TextBlock?

You can play with Background and apply a SystemColor.
Here is an example to get you started.

<TextBlock IsEnabled="True" 
        Background="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}" 
        Name="textBlock" 
        Text="TEST TextBlock" 
        Height="30" />

Your other option is to try the IsReadOnly property of the TextBox.


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.


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>

Tags:

C#

.Net

Wpf

Xaml