WP7-数据绑定ListboxItem';s的IsEnabled属性

本文关键字:IsEnabled 属性 数据绑定 ListboxItem WP7- | 更新日期: 2023-09-27 17:58:28

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

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

这导致AG_E_RUNTIME_MANAGED_UNKNOWN_ERROR在以下行失败:

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

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

WP7-数据绑定ListboxItem';s的IsEnabled属性

属性设置程序中的绑定是Silverlight 5的一项功能。Windows Phone 7使用Silverlight 3,因此此功能不可用。Windows Phone 7.1使用Silverlight 4,因此此功能甚至不是Windows Phone 7.5(Mango)的一部分。你要等很长时间!

有一些变通办法。请参阅博客文章随着平台的发展,解决方法也在发展(Better SetterValueBindingHelper使Silverlight Setters变得更好!)

您也可以将ListBox划分为子类,覆盖PrepareContainerForItemOverride以在添加每个ListBoxItem时添加绑定。请参阅快速加载Windows Phone 7导航列表控件中的示例,了解如何使用该覆盖。