我希望我的TextBlock显示为禁用(灰显),但当我将IsEnabled属性设置为false时,什么都没有发生,它仍然是黑色的:
<TextBlock Text="test" IsEnabled="False" />为什么会这样呢?
我也试过使用Label,但是由于某些原因它的尺寸太大了,所以它会弄乱我的布局。
发布于 2011-05-02 13:37:33
我认为这是使用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>发布于 2016-10-11 03:28:49
我试了一下,发现半不透明度与IsEnabled="False“给出了相同的结果。
<TextBlock Text="test" Opacity="0.5" />优点:它适合每种前景色。
发布于 2011-05-02 10:46:48
您可以使用背景并应用SystemColor。
这里有一个示例,可以帮助您入门。
<TextBlock IsEnabled="True"
Background="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}"
Name="textBlock"
Text="TEST TextBlock"
Height="30" />您的另一个选择是尝试TextBox的IsReadOnly属性。
https://stackoverflow.com/questions/5852963
复制相似问题