如何禁用TextBlock?

问题描述

| 我希望我的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属性。     

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...