1

In my ListBox 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>
Community
  • 1
  • 1
Qwertie
  • 16,354
  • 20
  • 105
  • 148
  • Strange, I copy pasted your XAML and I don't get any errors. – anivas Jul 04 '11 at 22:08
  • @anivas: thanks, but did you try attaching it to an actual ViewModel? Well, sadly I get this error even if I misspell both bindings.... looks like I just have to settle for a selection background that is almost invisible! – Qwertie Jul 04 '11 at 22:20

2 Answers2

1

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

H.B.
  • 166,899
  • 29
  • 327
  • 400
  • Thanks for trying. Is there any way to debug problems in XAML? – Qwertie Jul 05 '11 at 17:05
  • I do not know, i only know how to debug failing bindings; You could upload some project which reliably causes this problem so other people can have a look at it. Unless the problem can be reproduced i for one cannot help you right now i'm affraid. – H.B. Jul 05 '11 at 18:14
0

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.

Qwertie
  • 16,354
  • 20
  • 105
  • 148
  • It's not a bug, i totally overlooked that you could have been using an old version, in 3.5 it's probably handled as in Silverlight. – H.B. Nov 22 '11 at 21:22
  • What is that supposed to mean? What two features are you talking about? – H.B. Jan 11 '12 at 03:06
  • As the question says, Feature 1: binding the IsSelected property of each item to my ViewModel. Feature 2: use a Style to make selected items more visible when they don't have keyboard focus. – Qwertie Apr 10 '13 at 19:00