开发者

Why can't I combine these two ListBox features?

In my ListBox开发者_如何学C I wanted to bind the IsSelected property of each item to my ViewModel, and did so successfully. Then I wanted to make selected items more visible when they don't have keyboard focus, and this answer told me how to do so. Either feature alone works, but combining them causes the following exception on startup:

XamlParseException: A 'Binding' cannot be set on the 'Value' property of type 'Setter'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.

Here's my XAML:

<ListBox x:Name="objectList" ItemsSource="{Binding FilteredList}" SelectionMode="Extended">
    <ListBox.ItemContainerStyle>
        <Style TargetType="{x:Type ListBoxItem}">
            <Style.Resources>
                <!--Make unfocused selected items more visible-->
                <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="LightBlue" Opacity=".5"/>
            </Style.Resources>
            <!-- Support multiselect-->
            <Setter Property="IsSelected" Value="{Binding IsSelected}"/>
        </Style>
    </ListBox.ItemContainerStyle>
</ListBox>


Cannot reproduce this, that would be an error i would expect in Silverlight but not WPF. In SL you cannot create bindings using Setters.


I tried reproducing this in a new, clean, empty project and the error still occurs... if the .NET Framework version is 3.5. However, if I change the .NET Framework version to 4, the error disappears. It's probably a bug in .NET 3.5.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜