Uređivanje

Dijeli putem


Trigger Class

Definition

Represents a trigger that applies property values or performs actions conditionally.

public ref class Trigger : System::Windows::TriggerBase, System::Windows::Markup::IAddChild
public ref class Trigger : System::Windows::TriggerBase, System::ComponentModel::ISupportInitialize, System::Windows::Markup::IAddChild
[System.Windows.Markup.ContentProperty("Setters")]
public class Trigger : System.Windows.TriggerBase, System.Windows.Markup.IAddChild
[System.Windows.Markup.ContentProperty("Setters")]
[System.Windows.Markup.XamlSetTypeConverter("ReceiveTypeConverter")]
public class Trigger : System.Windows.TriggerBase, System.ComponentModel.ISupportInitialize, System.Windows.Markup.IAddChild
[<System.Windows.Markup.ContentProperty("Setters")>]
type Trigger = class
    inherit TriggerBase
    interface IAddChild
[<System.Windows.Markup.ContentProperty("Setters")>]
[<System.Windows.Markup.XamlSetTypeConverter("ReceiveTypeConverter")>]
type Trigger = class
    inherit TriggerBase
    interface IAddChild
    interface ISupportInitialize
[<System.Windows.Markup.ContentProperty("Setters")>]
[<System.Windows.Markup.XamlSetTypeConverter("ReceiveTypeConverter")>]
type Trigger = class
    inherit TriggerBase
    interface ISupportInitialize
    interface IAddChild
Public Class Trigger
Inherits TriggerBase
Implements IAddChild
Public Class Trigger
Inherits TriggerBase
Implements IAddChild, ISupportInitialize
Inheritance
Attributes
Implements

Examples

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>

Remarks

WPF defines properties that correspond to end-user actions, such as the IsMouseOver property that is set to true when the user hovers the cursor over a UIElement or the corresponding IsMouseOver property of a ContentElement. Representing end-user actions in property values, along with the Trigger element, allows WPF styles to change property values based on those end-user actions, all from within markup.

The properties changed by triggers are automatically reset to their previous value when the triggered condition is no longer satisfied. Triggers are optimized for transient states which are expected to change and return to original state, such as IsPressed on Button and IsSelected on ListBoxItem. The Property of interest must be a dependency property.

Note that you must specify both the Property and Value properties on a Trigger for the trigger to be meaningful. If one or both of the properties are not set, an exception is thrown.

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

There are other types of triggers. MultiTrigger allows you to apply changes based on the state of multiple properties. EventTrigger allows you to apply changes when an event occurs. DataTrigger and MultiDataTrigger are for data-bound properties.

Constructors

Trigger()

Initializes a new instance of the Trigger class.

Properties

DependencyObjectType

Gets the DependencyObjectType that wraps the CLR type of this instance.

(Inherited from DependencyObject)
Dispatcher

Gets the Dispatcher this DispatcherObject is associated with.

(Inherited from DispatcherObject)
EnterActions

Gets a collection of TriggerAction objects to apply when the trigger object becomes active. This property does not apply to the EventTrigger class.

(Inherited from TriggerBase)
ExitActions

Gets a collection of TriggerAction objects to apply when the trigger object becomes inactive. This property does not apply to the EventTrigger class.

(Inherited from TriggerBase)
IsSealed

Gets a value that indicates whether this instance is currently sealed (read-only).

(Inherited from DependencyObject)
Property

Gets or sets the property that returns the value that is compared with the Value property of the trigger. The comparison is a reference equality check.

Setters

Gets a collection of Setter objects, which describe the property values to apply when the specified condition has been met.

SourceName

Gets or sets the name of the object with the property that causes the associated setters to be applied.

Value

Gets or sets the value to be compared with the property value of the element. The comparison is a reference equality check.

Methods

CheckAccess()

Determines whether the calling thread has access to this DispatcherObject.

(Inherited from DispatcherObject)
ClearValue(DependencyProperty)

Clears the local value of a property. The property to be cleared is specified by a DependencyProperty identifier.

(Inherited from DependencyObject)
ClearValue(DependencyPropertyKey)

Clears the local value of a read-only property. The property to be cleared is specified by a DependencyPropertyKey.

(Inherited from DependencyObject)
CoerceValue(DependencyProperty)

Coerces the value of the specified dependency property. This is accomplished by invoking any CoerceValueCallback function specified in property metadata for the dependency property as it exists on the calling DependencyObject.

(Inherited from DependencyObject)
Equals(Object)

Determines whether a provided DependencyObject is equivalent to the current DependencyObject.

(Inherited from DependencyObject)
GetHashCode()

Gets a hash code for this DependencyObject.

(Inherited from DependencyObject)
GetLocalValueEnumerator()

Creates a specialized enumerator for determining which dependency properties have locally set values on this DependencyObject.

(Inherited from DependencyObject)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
GetValue(DependencyProperty)

Returns the current effective value of a dependency property on this instance of a DependencyObject.

(Inherited from DependencyObject)
InvalidateProperty(DependencyProperty)

Re-evaluates the effective value for the specified dependency property.

(Inherited from DependencyObject)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
OnPropertyChanged(DependencyPropertyChangedEventArgs)

Invoked whenever the effective value of any dependency property on this DependencyObject has been updated. The specific dependency property that changed is reported in the event data.

(Inherited from DependencyObject)
ReadLocalValue(DependencyProperty)

Returns the local value of a dependency property, if it exists.

(Inherited from DependencyObject)
ReceiveTypeConverter(Object, XamlSetTypeConverterEventArgs)

Handles cases where a type converter provides a value for a property of a Trigger object.

SetCurrentValue(DependencyProperty, Object)

Sets the value of a dependency property without changing its value source.

(Inherited from DependencyObject)
SetValue(DependencyProperty, Object)

Sets the local value of a dependency property, specified by its dependency property identifier.

(Inherited from DependencyObject)
SetValue(DependencyPropertyKey, Object)

Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property.

(Inherited from DependencyObject)
ShouldSerializeProperty(DependencyProperty)

Returns a value that indicates whether serialization processes should serialize the value for the provided dependency property.

(Inherited from DependencyObject)
ToString()

Returns a string that represents the current object.

(Inherited from Object)
VerifyAccess()

Enforces that the calling thread has access to this DispatcherObject.

(Inherited from DispatcherObject)

Explicit Interface Implementations

IAddChild.AddChild(Object)

Adds a child object.

IAddChild.AddText(String)

Adds the text content of a node to the object.

ISupportInitialize.BeginInit()

Signals the object that initialization is starting.

ISupportInitialize.EndInit()

Signals the object that initialization is complete.

Applies to