Export (0) Print
Expand All

Condition Class

Represents a condition for the MultiTrigger and the MultiDataTrigger, which apply changes to property values based on a set of conditions. This class cannot be inherited.

Namespace: System.Windows
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

public sealed class Condition
public final class Condition
public final class Condition
<Condition .../>

MultiTriggers and MultiDataTriggers allow you to set property values based on a set of conditions. A condition is satisfied when the property value of the element or data item matches the specified Value (reference equality check). If all specified conditions are satisfied, then the trigger is applied.

The following is a list of cases that will cause an exception:

  • For each Condition, you can only set either the Property property or the Binding property. If both properties are set, an exception is thrown.

  • If the Condition is for a MultiTrigger, the Property property cannot be null.

  • If the Condition is for a MultiDataTrigger, the Binding property cannot be null.

  • An exception is thrown if the specified Value is not valid for the type of the specified Property.

Note that if the Condition is for a MultiTrigger, the Property and Value properties must be set. If it is for a MultiDataTrigger, the Binding and Value properties must be set.

The following example contains two MultiTriggers. The first sets the MinWidth property value when the HasItems property is false and the Width property is Auto. The second one is similar but is for the MinHeight property.

<Style.Triggers>
  <Trigger Property="IsEnabled" Value="false">
    <Setter Property="Background" Value="#EEEEEE" />
  </Trigger>

  <MultiTrigger>
    <MultiTrigger.Conditions>
      <Condition Property="HasItems" Value="false" />
      <Condition Property="Width" Value="Auto" />
    </MultiTrigger.Conditions>
    <Setter Property="MinWidth" Value="120"/>
  </MultiTrigger>

  <MultiTrigger>
    <MultiTrigger.Conditions>
      <Condition Property="HasItems" Value="false" />
      <Condition Property="Height" Value="Auto" />
    </MultiTrigger.Conditions>
    <Setter Property="MinHeight" Value="95"/>
  </MultiTrigger>
</Style.Triggers>

See the Binding property for examples of conditions used in a MultiDataTrigger.

System.Object
  System.Windows.Condition

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

Community Additions

ADD
Show:
© 2014 Microsoft