I have a grid that has multiple rows. I want to hide/show one of those rows based on a property. Is that possible?
In my case, I have two grid rows. One has a property grid and the other a list box. The list box is bound to an object and the list items are bound to an array inside that object. What I want is to hide the row (including the list box) whenever the array is empty. So when my object’s array is empty, you should just see a window with a property grid and nothing else.
Thanks!
Yes. Bind the ListBox’s Visibility property to the object that contains the array. Then apply a custom value converter that will look at the array and see if it is empty. If it is empty, return Visibility.Collapsed. Otherwise, return Visibility.Visible. Then make sure your RowDefinition has a height of Auto, and it will automatically shrink to nothing when the ListBox is collapsed.
Your value converter will look something like this:
And your XAML should look something like this: