How can you get a XAML TextBlock to collapse when it contains no data?

后端 未结 3 579
臣服心动
臣服心动 2020-12-29 08:19

I want to tell WPF: \"If TextBlock contains no data, then don\'t show it.\"

TRY #1 with a simple trigger produces

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-29 09:03

    Either Try #2 or Try #3 should be fine - the problem is in the line where you are referencing the style - you need to use either 'Style="{StaticResource [KeyName]}"' or 'Style="{DynamicResource [KeyName]}"'.

    Try this (in Try #2):

            
        
    
    

    In Try 1 you reveal a limitation of current WPF versions: Triggers are not supported directly on elements.

提交回复
热议问题