WPF: Binding Visibility by string contents

后端 未结 5 1086
孤城傲影
孤城傲影 2021-01-07 22:55

Ok, so here is my XAML:


If InstanceName is null or an

5条回答
  •  一整个雨季
    2021-01-07 23:50

    By putting an extra property in your viewmodel that you can bind the Visibility attribute to:

    public class ViewModel
    {
       public string InstanceName {...}
       public Visibility InstanceVisibility 
       { 
          get 
          {
               return String.IsNullOrEmpty(InstanceName) ? Visibility.Collapsed : Visibility.Visible;
          }
    }
    

提交回复
热议问题