WPF text block gray text

I want to cross out text in a WPF text block. how to do it?

Relations Raju

+4
source share
5 answers

In C #:

textBox.Foreground = Brushes.Gray; 

In XAML:

 <TextBox Foreground="Gray" /> 

To disable it (the background will also change):

 textBox.IsEnabled = false; 
+6
source

You can set the TextBlock.Foreground property for 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" /> 
+4
source

The IsEnabled flag for textblock does not execute gray text. This post details the differences between textblock and label. It also shows that XAML adds an IsEnabled trigger for gray text.

+2
source

The problem with using a TextBox is that there is a field around it. If you use Label (with Content = "Foo"), you can switch the color of the text using IsEnabled. Otherwise, it behaves like a TextBlock for a short title / label.

0
source

Use a TextBox instead and set IsReadOnly = true or IsEnabled = false

-1
source

Source: https://habr.com/ru/post/1313431/


All Articles