TriggerBase Class
Represents the base class for specifying a conditional value within a Style object.
Assembly: PresentationFramework (in PresentationFramework.dll)
'Declaration <LocalizabilityAttribute(LocalizationCategory.None, Readability := Readability.Unreadable)> _ Public MustInherit Class TriggerBase _ Inherits DependencyObject 'Usage Dim instance As TriggerBase
This class is abstract; see Inheritance Hierarchy for derived non-abstract classes usable in XAML.
The WPF styling and templating model allows you to specify triggers within your Style, ControlTemplate, and DataTemplate. Essentially, TriggerBase is the base class for objects that allow you to apply changes when certain conditions (such as when a certain property value becomes true, or when an event occurs) are satisfied.
There are several different types of triggers: Trigger, MultiTrigger, EventTrigger, DataTrigger, and MultiDataTrigger.
The Trigger class is the simplest type of triggers. A Trigger object allows you to apply changes based on the value of a property. For example, the following example shows a named Style available to Button controls. The Style defines a Trigger element that changes the Foreground property of a button when the IsPressed property is true.
<Style x:Key="Triggers" TargetType="Button"> <Style.Triggers> <Trigger Property="IsPressed" Value="true"> <Setter Property = "Foreground" Value="Green"/> </Trigger> </Style.Triggers> </Style>
If you need to apply changes based on the state of multiple properties, you can use the MultiTrigger. For an example, see the MultiTrigger page.
The EventTrigger class allows you to apply changes when an event occurs. The following example contains two EventTrigger objects, one of which occurs when the mouse enters the element and the other occurs when the mouse leaves the element.
<Style TargetType="Rectangle"> <Setter Property="Width" Value="50" /> <Setter Property="Height" Value="50" /> <Setter Property="Margin" Value="20" /> <Setter Property="HorizontalAlignment" Value="Left" /> <Style.Triggers> <EventTrigger RoutedEvent="MouseEnter"> <BeginStoryboard> <Storyboard> <DoubleAnimation To="300" Duration="0:0:1.5" AccelerationRatio="0.10" DecelerationRatio="0.25" Storyboard.TargetProperty="(Canvas.Width)" /> </Storyboard> </BeginStoryboard> </EventTrigger> <EventTrigger RoutedEvent="MouseLeave"> <BeginStoryboard> <Storyboard> <DoubleAnimation Duration="0:0:1.5" AccelerationRatio="0.10" DecelerationRatio="0.25" Storyboard.TargetProperty="(Canvas.Width)" /> </Storyboard> </BeginStoryboard> </EventTrigger> </Style.Triggers> </Style>
These are also the DataTrigger and the MultiDataTrigger classes. These are similar to Trigger and MultiTrigger except that they are for data-bound properties.
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.