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.

System::Object
  System.Windows::Condition

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

[XamlSetTypeConverterAttribute(L"ReceiveTypeConverter")]
[XamlSetMarkupExtensionAttribute(L"ReceiveMarkupExtension")]
public ref class Condition sealed : ISupportInitialize
<Condition .../>

The Condition type exposes the following members.

  NameDescription
Public methodCondition()Initializes a new instance of the Condition class.
Public methodCondition(BindingBase, Object)Initializes a new instance of the Condition class.
Public methodCondition(DependencyProperty, Object)Initializes a new instance of the Condition class with the specified property and value. This constructor performs parameter validation.
Public methodCondition(DependencyProperty, Object, String)Initializes a new instance of the Condition class with the specified property, value, and the name of the source object.
Top

  NameDescription
Public propertyBindingGets or sets the binding that specifies the property of the condition. This is only applicable to MultiDataTrigger objects.
Public propertyPropertyGets or sets the property of the condition. This is only applicable to MultiTrigger objects.
Public propertySourceNameGets or sets the name of the object with the property that causes the associated setters to be applied. This is only applicable to MultiTrigger objects.
Public propertyValueGets or sets the value of the condition.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodStatic memberReceiveMarkupExtensionHandles cases where a markup extension provides a value for a property of a Condition object
Public methodStatic memberReceiveTypeConverterHandles cases where a type converter provides a value for a property of on aCondition object.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Explicit interface implemetationPrivate methodISupportInitialize::BeginInitInfrastructure. Signals the object that initialization is starting.
Explicit interface implemetationPrivate methodISupportInitialize::EndInitInfrastructure. Signals the object that initialization is complete.
Top

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.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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