How can I provide multiple conditions for data trigger in WPF?

Sumeru Suresh picture Sumeru Suresh · May 25, 2009 · Viewed 126.5k times · Source

How can I provide multiple conditions for data trigger in WPF?

Answer

Gishu picture Gishu · May 25, 2009

Use MultiDataTrigger type

<Style TargetType="ListBoxItem">
    <Style.Triggers>
      <DataTrigger Binding="{Binding Path=State}" Value="WA">
        <Setter Property="Foreground" Value="Red" />
      </DataTrigger>    
      <MultiDataTrigger>
        <MultiDataTrigger.Conditions>
          <Condition Binding="{Binding Path=Name}" Value="Portland" />
          <Condition Binding="{Binding Path=State}" Value="OR" />
        </MultiDataTrigger.Conditions>
        <Setter Property="Background" Value="Cyan" />
      </MultiDataTrigger>
    </Style.Triggers>
  </Style>