I've had a day full of Silverlight idiosynchrasies, including this little doozy:
<ComboBox>
<ComboBox.ItemContainerStyle>
<Style TargetType="ComboBoxItem">
<Setter Property="IsEnabled" Value="{Binding IsEnabled}"/>
</Style>
</ComboBox.ItemContainerStyle>
<ComboBoxItem>First</ComboBoxItem>
<ComboBoxItem>Second</ComboBoxItem>
</ComboBox>
The above fails with:
System.Windows.Markup.XamlParseException occurred
Message=Set property '' threw an exception. [Line: 88 Position: 52]
LineNumber=88
LinePosition=52
StackTrace:
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
InnerException: System.NotSupportedException
Message=Cannot set read-only property ''.
StackTrace:
at MS.Internal.XamlMemberInfo.SetValue(Object target, Object value)
at MS.Internal.XamlManagedRuntimeRPInvokes.SetValue(XamlTypeToken inType, XamlQualifiedObject& inObj, XamlPropertyToken inProperty, XamlQualifiedObject& inValue)
InnerException:
If I change {Binding IsEnabled}
to simply True
or False
, then it works fine.
I'm utterly confused because ComboBoxItem.IsEnabled
is a DependencyProperty
and is not readonly, so the error message is complete rubbish.
Any ideas how to fix this? Ultimately, all I want to do is have the IsEnabled
property on the ComboBoxItem
s to be bound to a property on my view model.
PS. Yes, I also tried binding ItemsSource
to my view model collection and ensuring that the IsEnabled
property actually existed on my view models. Same problem.