XAML - ListViewItem - IsEnabled Binding

£可爱£侵袭症+ 提交于 2019-12-11 01:31:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!