2010-06-21 48 views

回答

6

在C#:

textBox.Foreground = Brushes.Gray; 

在XAML:

<TextBox Foreground="Gray" /> 

要禁用它(會改變背景太):

textBox.IsEnabled = false; 
-1

使用文本框代替,並設置IsReadOnly = trueIsEnabled = false

4

您可以將TextBlock.Foreground屬性設置爲任何顏色(從技術上說,任何刷子)。如果你希望它是灰色的,只需設置:

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

如果你想讓它「已禁用」,您可以設置IsEnabled爲false:

<TextBlock Text="Foo" IsEnabled="false" /> 
+1

我想使用IsEnabled標誌。一旦我將它設置爲false,它沒有任何影響。可能是什麼問題呢? – user209293 2010-07-05 15:22:36

+0

@ user209293:你是如何將它設置爲false的? – 2010-07-05 16:23:51

+0

我在代碼方面做了。 textblock.Isenabled = false。 – user209293 2010-07-08 14:08:00

2

IsEnabled標誌爲textblock做不是灰色的文字。 This post詳細說明textblock和標籤之間的區別。它還顯示XAML在IsEnabled上添加觸發器以灰化文本。

0

使用TextBox的麻煩是有一個圓框。如果使用Label(內容=「Foo」),則可以使用IsEnabled切換文本顏色。否則,它的行爲就像TextBlock的簡短標題/標籤。