Binding Visibility to DataContext

前端 未结 1 1329
囚心锁ツ
囚心锁ツ 2021-01-21 01:42

I have a value converter that converts null to Visibility.Collapsed. Now I try to use it in a user control so that the whole control would collapse when it\'s DateContext is nul

1条回答
  •  温柔的废话
    2021-01-21 02:32

    In this case, when DataContext is null, binding will use value specified in TargetNullValue property. So simply set TargetNullValue=Collapsed and you're good to go :

    Visibility="{Binding TargetNullValue=Collapsed}"
    

    Reference : [How to Set TargetNullValue to Visibility.Collapsed in Binding]

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