Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
TriggerBase Class
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
TriggerBase Class

Updated: November 2007

Represents the base class for specifying a conditional value within a Style object.

Namespace:  System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)

Visual Basic (Declaration)
<LocalizabilityAttribute(LocalizationCategory.None, Readability := Readability.Unreadable)> _
Public MustInherit Class TriggerBase _
    Inherits DependencyObject
Visual Basic (Usage)
Dim instance As TriggerBase
C#
[LocalizabilityAttribute(LocalizationCategory.None, Readability = Readability.Unreadable)]
public abstract class TriggerBase : DependencyObject
Visual C++
[LocalizabilityAttribute(LocalizationCategory::None, Readability = Readability::Unreadable)]
public ref class TriggerBase abstract : public DependencyObject
J#
/** @attribute LocalizabilityAttribute(LocalizationCategory.None, Readability = Readability.Unreadable) */
public abstract class TriggerBase extends DependencyObject
JScript
public abstract class TriggerBase extends DependencyObject
XAML
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.

XAML
<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.

XAML
<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.

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 Vista

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.

.NET Framework

Supported in: 3.5, 3.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker