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

后端 未结 3 548
臣服心动
臣服心动 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:00

    I think the simplest way to do this would be to define a Converter which converts string to visibility.

       ...
    
       return string.IsNullOrEmpty(s) ? Visibility.Collapsed : Visibility.Visible;
    }
    

    Then just

提交回复
热议问题