Redigera

Dela via


MultiDataTrigger.Setters Property

Definition

Gets a collection of Setter objects that describe the property values to apply when all the conditions of the MultiDataTrigger are met.

public:
 property System::Windows::SetterBaseCollection ^ Setters { System::Windows::SetterBaseCollection ^ get(); };
public System.Windows.SetterBaseCollection Setters { get; }
member this.Setters : System.Windows.SetterBaseCollection
Public ReadOnly Property Setters As SetterBaseCollection

Property Value

A collection of Setter objects. The default value is an empty collection.

Examples

In the following example, the ItemsSource property of the ListBox is bound to Places, an ObservableCollection<T> of Place objects. Place objects have properties Name and State. The definition of Place and Places are not shown.

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.

Note that <MultiDataTrigger.Setters> is implicit.

<Window.Resources>
  <c:Places x:Key="PlacesData"/>

  <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>

  <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}"/>
    </Canvas>
  </DataTemplate>
</Window.Resources>

<StackPanel>
  <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}}"/>
</StackPanel>

Remarks

MultiDataTrigger enables you to start actions by using the EnterActions or ExitActions properties, or to set property values by using Setter objects when the bound data meet a set of conditions.

If there are two Setter objects in the same or different setter collections setting the same property, the Setter that is declared last is used.

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.

XAML Property Element Usage

<object>  
    zeroOrMoreSetters  
</object>  

XAML Values

zeroOrMoreSetters
Zero or more Setter objects.

Applies to

See also