问题描述
|
我希望我的TextBlock看起来已禁用(变灰),但是当我将
IsEnabled
属性设置为false时,什么也没有发生,但它保持黑色:
<TextBlock Text=\"test\" IsEnabled=\"False\" />
这是为什么?
我也尝试使用Label
,但是由于某种原因它的尺寸较大,因此会弄乱我的所有布局。
解决方法
我认为这是使用TextBlock的正确方法:
<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>
,我玩了一点,发现一半的不透明度给与IsEnabled = \“ False \”相同的结果。
<TextBlock Text=\"test\" Opacity=\"0.5\" />
优点:它适合每种前景颜色。
,您可以使用Background并应用SystemColor。
这是一个使您入门的示例。
<TextBlock IsEnabled=\"True\"
Background=\"{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}\"
Name=\"textBlock\"
Text=\"TEST TextBlock\"
Height=\"30\" />
您的另一个选择是尝试使用TextBox的IsReadOnly属性。