.NET Framework Class Library
MultiDataTrigger..::.Conditions Property

Gets a collection of Condition objects. Changes to property values are applied when all the conditions in the collection are met.

Namespace:  System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
Syntax

Visual Basic (Declaration)
Public ReadOnly Property Conditions As ConditionCollection
Visual Basic (Usage)
Dim instance As MultiDataTrigger
Dim value As ConditionCollection

value = instance.Conditions
C#
public ConditionCollection Conditions { get; }
Visual C++
public:
property ConditionCollection^ Conditions {
    ConditionCollection^ get ();
}
JScript
public function get Conditions () : ConditionCollection
XAML Property Element Usage
<object>
  <object.Conditions>
    zeroOrMoreConditions
  </object.Conditions>
</object>

XAML Values

zeroOrMoreConditions

Zero or more Condition objects.

Property Value

Type: System.Windows..::.ConditionCollection
A collection of Condition objects. The default is an empty collection.
Remarks

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. That value is first converted to the type of the value of the binding, if possible, and then the two values are compared using the Object.Equals method. The MultiTrigger applies the associated setters or actions when all of the conditions are true (binary AND operation).

For a MultiDataTrigger, each condition in the collection must set both the Binding and Value properties. For more information, see Binding.

Examples

In the following example, the ItemsSource property of the ListBox is bound to Places, an ObservableCollection<(Of <(T>)>) 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>
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0
See Also

Reference

Other Resources

Tags :


Page view tracker