【问题标题】:WP7 - Databind ListboxItem's IsEnabled PropertyWP7 - 数据绑定 ListboxItem 的 IsEnabled 属性
【发布时间】:2011-06-07 06:52:04
【问题描述】:

我有一个 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)?

【问题讨论】:

    标签: c# xaml data-binding windows-phone-7


    【解决方案1】:

    属性设置器内的绑定是Silverlight 5 功能。 Windows Phone 7 使用 Silverlight 3,因此该功能不可用。 Windows Phone 7.1 使用 Silverlight 4,因此此功能甚至不是 Windows Phone 7.5 (Mango) 的一部分。你要等很久了!

    有一些解决方法。请参阅博文As the platform evolves, so do the workarounds (Better SetterValueBindingHelper makes Silverlight Setters better-er!)

    您还可以继承 ListBox,覆盖 PrepareContainerForItemOverride 以在添加每个 ListBoxItem 时添加您的绑定。请参阅 A Fast Loading Windows Phone 7 NavigationList Control 中的示例以使用该覆盖。

    【讨论】:

    • 完美,我最终继承了 ListBox。非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多