XAML - ListViewItem的 - IsEnabled绑定 [英] XAML - ListViewItem - IsEnabled Binding

查看:187
本文介绍了XAML - ListViewItem的 - IsEnabled绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请把我从我的痛苦:

<ListView.ItemContainerStyle>
    <Style TargetType="ListViewItem">
        <Setter Property="IsEnabled" Value="{Binding MyBoolField}" />
    </Style>
</ListView.ItemContainerStyle>



其中, MyBoolField 是每个可用的属性在 ListView项的分配的ItemsSource ,并键入布尔

Where MyBoolField is a property available on each item in the ListView's assigned ItemsSource, and is of course of type bool.

期望的行为是每个 IsEnabled 属性 ListViewItem的绑定到它包含(从的ListView元素的对象 MyBoolField 属性的ItemsSource )。然而,上面的例子不关注这个绑定,并且总是真正

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.

也许是有用知道绑定在成立分配给该的DataTemplate 的ListView 的ItemTemplate 所有的工作好吗,所以这个问题是有希望不是根本性/愚蠢的。

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.


  • 有一个在调试输出窗口中没有相关的输出。

  • 其他绑定 MyBoolField 物业工作正常,因为这样的基础数据源被正确提供一个布尔值,这似乎是仅由在此上下文中结合它的一个问题。

  • 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.

推荐答案

好吧,阅读这篇文章似乎它的一个已知的WinRT的限制,也许你找到一些有用的东西在那里。
有一件事我也想尝试,因为在该职位的任择议定书表示关于那是后话。使用绑定,并使用路径= DataContext.MyBoolField

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

进一步阅读,这是从Silverlight的限制,它的WinRT是建立在。因此,这个是一个解决办法也应为WinRT的

Further reading, this is a limitation from Silverlight, which WinRT was build upon. So this is a workaround which should also work for WinRT

这篇关于XAML - ListViewItem的 - IsEnabled绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆