7

I'm having trouble with a Condition for a MultiTrigger. If I do the following:

<Condition Binding="{Binding RelativeSource={RelativeSource
    AncestorType={x:Type ListView}}}" Property="IsEnabled" Value="True"/>

Then I get this exception:

Condition cannot use both Property and Binding. Error at object 'System.Windows.Condition' in markup file

However, when I do the following:

<Condition Binding="{Binding RelativeSource={RelativeSource
    AncestorType={x:Type ListView}}, Path=IsEnabled}" Value="True"/>

Then I get this exception:

Must specify both Property and Value for Trigger. Error at object 'System.Windows.Condition' in markup file

What gives? If it matters, here's the entire trigger:

<MultiTrigger>
    <MultiTrigger.Conditions>
        <Condition Binding="{Binding Path=IsSelected}" Value="True"/>
        <Condition Binding="{Binding Path=ItemsControl.AlternationIndex}"
                   Value="0"/>
        <Condition Binding="{Binding RelativeSource={RelativeSource
            AncestorType={x:Type ListView}}, Path=IsEnabled}"
                   Value="True"/>
    </MultiTrigger.Conditions>
    <Setter Property="Background"
            Value="{StaticResource evenSelected}" />
    <Setter Property="BorderBrush"
            Value="{StaticResource evenSelectedBorder}" />
</MultiTrigger>
Sarah Vessels
  • 30,930
  • 33
  • 155
  • 222

1 Answers1

12

The API in this case is confusing. Condition is used for two different types of multi-triggers, and the properties used are different. When using MultiTrigger, you will use the Property and Value properties. When using MultiDataTrigger (which is what you need), you specify a Binding and a Value. So, if you just switch your code to use a MultiDataTrigger, you'll be good to go:

<MultiDataTrigger>
    <MultiDataTrigger.Conditions>
        <Condition Binding="{Binding Path=IsSelected}" Value="True"/>
        <Condition Binding="{Binding Path=ItemsControl.AlternationIndex}"
                   Value="0"/>
        <Condition Binding="{Binding RelativeSource={RelativeSource
            AncestorType={x:Type ListView}}, Path=IsEnabled}"
                   Value="True"/>
    </MultiDataTrigger.Conditions>
    <Setter Property="Background"
            Value="{StaticResource evenSelected}" />
    <Setter Property="BorderBrush"
            Value="{StaticResource evenSelectedBorder}" />
</MultiDataTrigger>
Abe Heidebrecht
  • 30,090
  • 7
  • 62
  • 66
  • 1
    Great, thanks! I no longer get the `XamlParseException`, though I must not have the last `Condition` right yet, because my setters don't work anymore on enabled `ListView` items. – Sarah Vessels Jan 10 '11 at 19:08