[英]How to disable 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" />
优点:它适合每种前景色。
您可以使用背景并应用 SystemColor。
这是一个帮助您入门的示例。
<TextBlock IsEnabled="True"
Background="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}"
Name="textBlock"
Text="TEST TextBlock"
Height="30" />
您的另一个选择是尝试 TextBox 的 IsReadOnly 属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.