问题
Please put me out of my misery:
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="IsEnabled" Value="{Binding MyBoolField}" />
</Style>
</ListView.ItemContainerStyle>
Where MyBoolField
is a property available on each item in the ListView
's assigned ItemsSource
, and is of course of type bool
.
The desired behaviour is that the IsEnabled
property of each ListViewItem
is bound to the MyBoolField
property of the object it contains (an element from the ListView
's ItemsSource
). The example above however pays no attention to this binding and is always true
.
If I set the value to false
statically, the item becomes disabled as expected.
I can only assume this is an issue of scoping, or a restriction on the use of bindings in this particular scenario, however I am unable to find any documentation to support this.
Perhaps it is useful to know that bindings set up in the DataTemplate
assigned to this ListView
's ItemTemplate
all work okay, so the problem is hopefully not that fundamental/stupid.
Points from the Comments
- There is no relevant output in the debug 'Output' window.
- Binding the
MyBoolField
property elsewhere works fine, as such the underlying data source is providing a Boolean value correctly and this seems to be solely an issue of binding it in this context.
回答1:
Ok, reading this post it seems that its a known limitation of WinRT, maybe you find something useful there.
One thing i would also try, because the OP in that post said something regarding that is. Using a Self
binding, and use Path=DataContext.MyBoolField
Further reading, this is a limitation from Silverlight, which WinRT was build upon. So this is a workaround which should also work for WinRT
来源:https://stackoverflow.com/questions/12682858/xaml-listviewitem-isenabled-binding