I have a list of objects contained in an IEnumerable<>.
I would like to set the visibility of a control based on the count of this list. I have tried:
Visibility="{Binding MyList.Count>0?Collapsed:Visible, Mode=OneWay}"
But this doesn’t work. I tried binding MyList.Count to the text in a text block to ensure that the count value was correct, and it is. It just doesn’t seem to set the visibility correctly.
You cannot use logical or code-expressions in bindings (it expects a
PropertyPath). Either use a converter or triggers, which is what i would do:(You can of course refactor the style into a resource if you wish.)