Search code examples
xamlresourcedictionary

'Collapsed' is not a valid value for the 'System.Windows.UIElement.Visibility' property on a Setter


I'm struggling with something but I know what is going wrong, just not why.

The following entry in my resource dictionary works

 <Setter Property="Visibility" Value="Collapsed" />

I need to make this dynamic and bind the value to a static property, and this is where it is failing.

<Setter Property="Visibility" Value="{x:Static loc:StateMachine.CollaspseOrVisibleString}" />

and returns the following exception

'Collapsed' is not a valid value for the 'System.Windows.UIElement.Visibility' property on a Setter.

The static property is definitely returning the string "Collapsed" so I'm lost as to why it's not valid.


Solution

  • You need to bind to something that returns a value of the Visibility enumeration type, not a string:

    http://msdn.microsoft.com/en-us/library/system.windows.visibility%28v=vs.95%29.aspx

    i.e. change your StateMachine.CollapseOrVisible property return type to 'Visibility' and have it return Visibility.Collapsed (the enumeration value, not the string)