WPF: How to make empty TextBlock not to occupy space?

后端 未结 2 2057
一个人的身影
一个人的身影 2021-02-20 09:28

Let\'s say that I have a simple layout such as this:


  
  

        
相关标签:
2条回答
  • You want to set the visibility of the textbox to "Collapsed".

    Visibility can be either:
    Visible - Self explanatory
    Hidden - Invisible but still takes up space
    Collapsed - Invisible and takes up no space

    Edit: You should probably set up a trigger, like so:

    <Trigger Property="Text" Value="{x:Null}">
        <Setter Property="Visibility" Value="Collapsed"/>
    </Trigger>
    
    0 讨论(0)
  • 2021-02-20 09:55

    You may want to try this:

    <TextBlock.Style>
        <Style TargetType="{x:Type TextBlock}">
            <Style.Triggers>
                <Trigger Property="Text" Value="">
                    <Setter Property="Visibility" Value="Collapsed"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </TextBlock.Style>
    

    This should fix the empty space issue based on a Null / Empty Binding.

    0 讨论(0)
提交回复
热议问题