Editar

Partilhar via


DataTrigger.Setters Property

Definition

Gets a collection of Setter objects, which describe the property values to apply when the data item meets the specified condition.

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

The default value is null.

Examples

The following example shows two DataTrigger objects that are defined in a DataTemplate. The DataTemplate is applied to AuctionItem data objects (not shown in this example), which have the property SpecialFeatures.

The first DataTrigger is specified such that if the data object has a SpecialFeatures value of Color, then the item is displayed with a DodgerBlue background with Navy titles. If the data object has a SpecialFeatures value of Highlight, then the second DataTrigger will be active, causing the item to be displayed with an Orange border with a star.

For the complete sample, see Data Binding Demo.

<DataTemplate.Triggers>
    <DataTrigger Binding="{Binding Path=SpecialFeatures}">
        <DataTrigger.Value>
            <src:SpecialFeatures>Color</src:SpecialFeatures>
        </DataTrigger.Value>
      <DataTrigger.Setters>
        <Setter Property="BorderBrush" Value="DodgerBlue" TargetName="border" />
        <Setter Property="Foreground" Value="Navy" TargetName="descriptionTitle" />
        <Setter Property="Foreground" Value="Navy" TargetName="currentPriceTitle" />
        <Setter Property="BorderThickness" Value="3" TargetName="border" />
        <Setter Property="Padding" Value="5" TargetName="border" />
      </DataTrigger.Setters>
    </DataTrigger>
    <DataTrigger Binding="{Binding Path=SpecialFeatures}">
        <DataTrigger.Value>
            <src:SpecialFeatures>Highlight</src:SpecialFeatures>
        </DataTrigger.Value>
        <Setter Property="BorderBrush" Value="Orange" TargetName="border" />
        <Setter Property="Foreground" Value="Navy" TargetName="descriptionTitle" />
        <Setter Property="Foreground" Value="Navy" TargetName="currentPriceTitle" />
        <Setter Property="Visibility" Value="Visible" TargetName="star" />
        <Setter Property="BorderThickness" Value="3" TargetName="border" />
        <Setter Property="Padding" Value="5" TargetName="border" />
    </DataTrigger>
</DataTemplate.Triggers>

Remarks

XAML Property Element Usage

<object>  
  <object.Setters>  
    ZeroOrMoreSetters  
  </object.Setters>  
</object>  

XAML Values

ZeroOrMoreSetters
Zero or more Setter objects.

A DataTrigger allows you to start actions or to use Setters to apply property values when the data item meets a specified condition.

If there is more than one setter setting the same property in the same setter collection, the setter that is declared last is used.

The Setters property of a DataTrigger object can only consist of Setter objects. Adding a Setter child to a DataTrigger object implicitly adds it to the SetterBaseCollection for the DataTrigger object. EventSetter objects are not supported; only Style.Setters supports EventSetter objects.

Applies to

See also