MultiDataTrigger Class

Represents a trigger that applies property values or performs actions when the bound data meet a set of conditions.

Namespace: System.Windows
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:

<ContentPropertyAttribute("Setters")> _
Public NotInheritable Class MultiDataTrigger
	Inherits TriggerBase
	Implements IAddChild
Dim instance As MultiDataTrigger

/** @attribute ContentPropertyAttribute("Setters") */ 
public final class MultiDataTrigger extends TriggerBase implements IAddChild
public final class MultiDataTrigger extends TriggerBase implements IAddChild

A MultiDataTrigger object is similar to a MultiTrigger, except that the conditions of a MultiDataTrigger are based on property values of bound data instead of those of a UIElement. In a MultiDataTrigger, a condition is met when the property value of the data item matches the specified Value. You can then use setters or the EnterActions and ExitActions properties to apply changes or start actions when all of the conditions are met.

The Setters property of a MultiDataTrigger object can only consist of Setter objects. Adding a Setter child to a MultiDataTrigger object implicitly adds it to the SetterBaseCollection for the MultiDataTrigger object. EventSetter objects are not supported; only Style.Setters supports EventSetter objects.

For information about when to use triggers and when to use other techniques, see Data Templating Overview.

In the following example, the ItemsSource property of the ListBox is bound to Places, an ObservableCollection of Place objects. Place objects have properties Name and State. The definition of Place and Places are not shown but can be found in the Binding Using Data Triggers Sample.

Each ListBoxItem of the ListBox displays a Place object. The Style in the example is applied to each ListBoxItem. The Condition elements of the MultiDataTrigger specify that if the Name and State of the Place data item are Portland and OR respectively, then the background of corresponding ListBoxItem is set to Cyan.

  <c:Places x:Key="PlacesData"/>

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

  <DataTemplate DataType="{x:Type c:Place}">
    <Canvas Width="160" Height="20">
      <TextBlock FontSize="12"
             Width="130" Canvas.Left="0" Text="{Binding Path=Name}"/>
      <TextBlock FontSize="12" Width="30"
                 Canvas.Left="130" Text="{Binding Path=State}"/>

  <TextBlock FontSize="18" Margin="5" FontWeight="Bold"
    HorizontalAlignment="Center">Data Trigger Sample</TextBlock>
  <ListBox Width="180" HorizontalAlignment="Center" Background="Honeydew"
    ItemsSource="{Binding Source={StaticResource PlacesData}}"/>

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0