WP7 - Databind ListboxItem的IsEnabled属性 [英] WP7 - Databind ListboxItem's IsEnabled Property

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

问题描述

我有一个Listbox,其ItemsSource属性数据绑定到一个对象的集合。集合中的每个对象都有一个启用属性,我想绑定到它们各自的ListboxItem。我试过这个方法:

 < ListBox ItemsSource ={Binding MyList}> 
< ListBox.ItemContainerStyle>
< Style TargetType =ListBoxItem>
< Setter Property =IsEnabledValue ={Binding Enabled}/>
< / Style>
< /ListBox.ItemContainerStyle>
< / ListBox>

这导致AG_E_RUNTIME_MANAGED_UNKNOWN_ERROR在这一行失败:

 < Setter Property =IsEnabledValue ={Binding Enabled}/> 

如何绑定ListboxItems上的IsEnabled属性(使用Windows Phone 7)?

解决方案

属性设置器中的绑定是一个 Silverlight 5 功能。 Windows Phone 7使用Silverlight 3,因此此功能不可用。 Windows Phone 7.1使用Silverlight 4,所以这个功能甚至不是Windows Phone 7.5(芒果)的一部分。你手上有一个漫长的等待!



有一些解决方法。参见博客文章随着平台的发展,解决方法也变得如此(Better SetterValueBindingHelper使Silverlight Setters更好地使用)



您还可以将 ListBox 子类化,覆盖 PrepareContainerForItemOverride 添加每个 ListBoxItem 的绑定。参见 快速加载Windows Phone 7 NavigationList控件 使用该覆盖。


I have a Listbox with its ItemsSource property databound to a collection of objects. Each of the objects in the collection have an Enabled property which I would like to bind to their respective ListboxItem. I tried this approach:

<ListBox ItemsSource="{Binding MyList}">
    <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Setter Property="IsEnabled" Value="{Binding Enabled}" />
        </Style>
    </ListBox.ItemContainerStyle>
</ListBox>

This results in AG_E_RUNTIME_MANAGED_UNKNOWN_ERROR failing on this line:

<Setter Property="IsEnabled" Value="{Binding Enabled}" />

How do I bind to the IsEnabled property on ListboxItems (using Windows Phone 7)?

解决方案

Binding within property setters is a Silverlight 5 feature. Windows Phone 7 uses Silverlight 3, so this feature is not available. Windows Phone 7.1 uses Silverlight 4, so this feature is not even part of Windows Phone 7.5 (Mango). You have a long wait on your hands!

There are some workarounds out there. See the blog post As the platform evolves, so do the workarounds (Better SetterValueBindingHelper makes Silverlight Setters better-er!).

You could also subclass ListBox, overriding PrepareContainerForItemOverride to add your binding as each ListBoxItem is added. See an example in A Fast Loading Windows Phone 7 NavigationList Control for using that override.

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

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