How to disable TextBlock?

前端 未结 3 1723
逝去的感伤
逝去的感伤 2021-02-05 02:07

I want my TextBlock to look disabled (grayed out) but when I set IsEnabled property to false nothing happens, it stays black:



        
相关标签:
3条回答
  • 2021-02-05 02:12

    You can play with Background and apply a SystemColor.
    Here is an example to get you started.

    <TextBlock IsEnabled="True" 
            Background="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}" 
            Name="textBlock" 
            Text="TEST TextBlock" 
            Height="30" />
    

    Your other option is to try the IsReadOnly property of the TextBox.

    0 讨论(0)
  • 2021-02-05 02:16

    I played a little and found out that half opacity is giving the same resultat as IsEnabled="False".

    <TextBlock Text="test" Opacity="0.5" />
    

    Advantage : it fits to every Foreground color.

    0 讨论(0)
  • 2021-02-05 02:30

    This would be the proper way to do it with a TextBlock i think:

    <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>
    
    0 讨论(0)
提交回复
热议问题