开发者

WP7 - Databind ListboxItem's IsEnabled Property

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 开发者_如何学PythonAG_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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜