Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide a control if the underlying DataContext is null?

Tags:

I have an object in my view model that has a bunch of properties, some of them will occasionally be null. I don't want to just show some controls if these particular controls are null. How would I go about hiding the control if the bind is null? I was thinking of some sort of converter, but don't know how I'd go about doing it exactly. Any ideas?

edit: sorry, I should mention that this will also be in Silverlight, so I'm not sure if Style triggers would work...?

like image 962
Harry Avatar asked Mar 16 '11 10:03

Harry


1 Answers

This approach is easier:

<CheckBox Visibility="{Binding Path=checkedField, TargetNullValue=Collapsed }"> 

When the bound property checkedField is null, the Visibility will be set to Collapsed.

like image 104
bugfixr Avatar answered Oct 27 '22 14:10

bugfixr