Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Text block gray out text

Tags:

wpf

textblock

I want to gray out text in the WPF text block. how do i make it?

Regards Raju

like image 713
user209293 Avatar asked Jun 21 '10 19:06

user209293


5 Answers

On C#:

textBox.Foreground = Brushes.Gray;

On XAML:

<TextBox Foreground="Gray" />

To disable it (will change background too):

textBox.IsEnabled = false;
like image 164
Carlo Avatar answered Nov 09 '22 23:11

Carlo


The IsEnabled flag for a textblock does not grey the text. This post details the differences between textblock and label. It also shows the XAML to add a trigger on IsEnabled to grey the text.

like image 33
RichardU Avatar answered Nov 09 '22 23:11

RichardU


You can set the TextBlock.Foreground property to any color (technically, any Brush). If you want it to be grayed out, just set:

<TextBlock Text="Foo" Foreground="Gray" />

If you want it to look "disabled", you can set IsEnabled to false:

<TextBlock Text="Foo" IsEnabled="false" />
like image 38
Reed Copsey Avatar answered Nov 10 '22 00:11

Reed Copsey


TextBlocks do not grayout automaticly when disabled

you can use a style to do this for you

    <Style x:Key="DisableEnableTextBlock" TargetType="{x:Type TextBlock}">
    <Style.Triggers>
        <Trigger Property="IsEnabled" Value="True">
            <Setter Property="Opacity" Value="1" />
        </Trigger>
        <Trigger Property="IsEnabled" Value="False">
            <Setter Property="Opacity" Value=".5" />
        </Trigger>
    </Style.Triggers>
</Style>
like image 42
Paul Baxter Avatar answered Nov 09 '22 23:11

Paul Baxter


The trouble with using the TextBox is that there's a box round it. If you use Label (with Content="Foo") then you can toggle the text colour with IsEnabled. Otherwise it behaves like TextBlock for a short heading/label.

like image 32
user3033320 Avatar answered Nov 09 '22 23:11

user3033320