System.Windows


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

Espace de noms: System.Windows
Assembly : PresentationFramework (dans presentationframework.dll)
Espace de noms XML :  http://schemas.microsoft.com/winfx/2006/xaml/presentation

Syntaxe

Visual Basic (Déclaration)
<ContentPropertyAttribute("Setters")> _
Public NotInheritable Class MultiDataTrigger
    Inherits TriggerBase
    Implements IAddChild
Visual Basic (Utilisation)
Dim instance As MultiDataTrigger
C#
[ContentPropertyAttribute("Setters")] 
public sealed class MultiDataTrigger : TriggerBase, IAddChild
C++
[ContentPropertyAttribute(L"Setters")] 
public ref class MultiDataTrigger sealed : public TriggerBase, IAddChild
J#
/** @attribute ContentPropertyAttribute("Setters") */ 
public final class MultiDataTrigger extends TriggerBase implements IAddChild
JScript
ContentPropertyAttribute("Setters") 
public final class MultiDataTrigger extends TriggerBase implements IAddChild
Utilisation des éléments objets XAML
<MultiDataTrigger>
  Setters
</MultiDataTrigger>
Notes

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.

Exemple

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.

XAML
<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>
Hiérarchie d'héritage

System.Object
   System.Windows.Threading.DispatcherObject
     System.Windows.DependencyObject
       System.Windows.TriggerBase
        System.Windows.MultiDataTrigger
Sécurité des threads

Les membres statiques publics (Shared en Visual Basic) de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.
Plateformes

Microsoft .NET Framework 3.0 est pris en charge sur Windows Vista, Microsoft Windows XP SP2 et Windows Server 2003 SP1.

Informations de version

.NET Framework

Prise en charge dans : 3.0
Voir aussi

Mots clés :


Page view tracker