Trigger 類別

定義

表示套用屬性值,或有條件地執行動作的觸發程序。Represents a trigger that applies property values or performs actions conditionally.

public ref class Trigger : System::Windows::TriggerBase, System::ComponentModel::ISupportInitialize, 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
type Trigger = class
    inherit TriggerBase
    interface IAddChild
    interface ISupportInitialize
Public Class Trigger
Inherits TriggerBase
Implements IAddChild, ISupportInitialize
繼承
屬性
實作

範例

下列範例會顯示可供 Button 控制項使用的已命名 StyleThe following example shows a named Style available to Button controls. Style 定義 Trigger 元素,在 IsPressed 屬性為 true時,變更按鈕的 Foreground 屬性。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>

備註

WPFWPF 定義對應至使用者動作的屬性,例如當使用者將游標停留在 IsMouseOverUIElement 或對應的 ContentElement屬性時,設定為 trueIsMouseOver 屬性。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. 表示屬性值中的使用者動作,以及 Trigger 專案,可讓 WPFWPF 樣式根據這些使用者動作來變更屬性值,這些都是從標記內完成。Representing end-user actions in property values, along with the Trigger element, allows WPFWPF 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. 觸發程式已針對預期會變更並回到原始狀態的暫時性狀態進行優化,例如在 ListBoxItemButtonIsSelectedIsPressedTriggers are optimized for transient states which are expected to change and return to original state, such as IsPressed on Button and IsSelected on ListBoxItem. Property 的相關內容必須是相依性屬性。The Property of interest must be a dependency property.

請注意,您必須在 Trigger 上指定 PropertyValue 屬性,觸發程式才有意義。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.

Trigger 物件的 Setters 屬性只能包含 Setter 物件。The Setters property of a Trigger object can only consist of Setter objects. Setter 子系加入 Trigger 物件中,會隱含地將它加入 Trigger 物件的 SetterBaseCollection 中。Adding a Setter child to a Trigger object implicitly adds it to the SetterBaseCollection for the Trigger object. 不支援 EventSetter 物件;只有 Style.Setters 支援 EventSetter 物件。EventSetter objects are not supported; only Style.Setters supports EventSetter objects.

還有其他類型的觸發程式。There are other types of triggers. MultiTrigger 可讓您根據多個屬性的狀態來套用變更。MultiTrigger allows you to apply changes based on the state of multiple properties. EventTrigger 可讓您在事件發生時套用變更。EventTrigger allows you to apply changes when an event occurs. DataTriggerMultiDataTrigger 適用于資料系結屬性。DataTrigger and MultiDataTrigger are for data-bound properties.

建構函式

Trigger()

初始化 Trigger 類別的新執行個體。Initializes a new instance of the Trigger class.

屬性

DependencyObjectType

取得包裝此執行個體之 DependencyObjectType 型別的 CLRCLRGets the DependencyObjectType that wraps the CLRCLR type of this instance.

(繼承來源 DependencyObject)
Dispatcher

取得與這個 Dispatcher 關聯的 DispatcherObjectGets the Dispatcher this DispatcherObject is associated with.

(繼承來源 DispatcherObject)
EnterActions

取得要在觸發程序物件變成作用中時所套用的 TriggerAction 物件集合。Gets a collection of TriggerAction objects to apply when the trigger object becomes active. 此屬性不適用於 EventTrigger 類別。This property does not apply to the EventTrigger class.

(繼承來源 TriggerBase)
ExitActions

取得 TriggerAction 物件的集合,在觸發程序物件變成非作用時套用。Gets a collection of TriggerAction objects to apply when the trigger object becomes inactive. 此屬性不適用於 EventTrigger 類別。This property does not apply to the EventTrigger class.

(繼承來源 TriggerBase)
IsSealed

取得值,這個值表示此執行個體目前是否已密封 (唯讀)。Gets a value that indicates whether this instance is currently sealed (read-only).

(繼承來源 DependencyObject)
Property

取得或設定屬性,傳回與觸發程式之 Value 屬性相比較的值。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

取得 Setter 物件的集合,這些物件描述滿足指定的條件時要套用的屬性值。Gets a collection of Setter objects, which describe the property values to apply when the specified condition has been met.

SourceName

取得或設定物件名稱,這個物件具有會套用相關聯之 setter 的屬性。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.

方法

CheckAccess()

判斷呼叫的執行是否可以存取這個 DispatcherObjectDetermines whether the calling thread has access to this DispatcherObject.

(繼承來源 DispatcherObject)
ClearValue(DependencyProperty)

清除屬性的區域數值。Clears the local value of a property. 要清除的屬性是由 DependencyProperty 識別項所指定。The property to be cleared is specified by a DependencyProperty identifier.

(繼承來源 DependencyObject)
ClearValue(DependencyPropertyKey)

清除唯讀屬性的區域數值。Clears the local value of a read-only property. 要清除的屬性是由 DependencyPropertyKey 所指定。The property to be cleared is specified by a DependencyPropertyKey.

(繼承來源 DependencyObject)
CoerceValue(DependencyProperty)

強制轉型所指定相依性屬性的值。Coerces the value of the specified dependency property. 完成方式是叫用存在於呼叫 CoerceValueCallback 之相依性屬性的屬性中繼資料中所指定的任何 DependencyObject 函式。This is accomplished by invoking any CoerceValueCallback function specified in property metadata for the dependency property as it exists on the calling DependencyObject.

(繼承來源 DependencyObject)
Equals(Object)

判斷提供的 DependencyObject 和目前的 DependencyObject 是否相等。Determines whether a provided DependencyObject is equivalent to the current DependencyObject.

(繼承來源 DependencyObject)
GetHashCode()

取得這個 DependencyObject 的雜湊碼。Gets a hash code for this DependencyObject.

(繼承來源 DependencyObject)
GetLocalValueEnumerator()

建立特定的列舉值,以判斷哪些相依性屬性在此 DependencyObject 上具有本機設定的值。Creates a specialized enumerator for determining which dependency properties have locally set values on this DependencyObject.

(繼承來源 DependencyObject)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
GetValue(DependencyProperty)

傳回 DependencyObject 的這個執行個體上之相依性屬性的目前有效值。Returns the current effective value of a dependency property on this instance of a DependencyObject.

(繼承來源 DependencyObject)
InvalidateProperty(DependencyProperty)

重新評估指定相依性屬性的有效值。Re-evaluates the effective value for the specified dependency property.

(繼承來源 DependencyObject)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
OnPropertyChanged(DependencyPropertyChangedEventArgs)

每當這個 DependencyObject 上任何相依性屬性的有效值已更新時叫用。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.

(繼承來源 DependencyObject)
ReadLocalValue(DependencyProperty)

傳回相依性屬性的區域值 (如果存在)。Returns the local value of a dependency property, if it exists.

(繼承來源 DependencyObject)
ReceiveTypeConverter(Object, XamlSetTypeConverterEventArgs)

處理型別轉換子對 Trigger 物件的屬性提供值的情況。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.

(繼承來源 DependencyObject)
SetValue(DependencyProperty, Object)

設定相依性屬性的區域值 (由相依性屬性的識別碼所指定)。Sets the local value of a dependency property, specified by its dependency property identifier.

(繼承來源 DependencyObject)
SetValue(DependencyPropertyKey, Object)

設定唯讀相依性屬性的區域數值 (由相依性屬性的 DependencyPropertyKey 識別項所指定)。Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property.

(繼承來源 DependencyObject)
ShouldSerializeProperty(DependencyProperty)

傳回值,這個值表示序列化程序是否應該序列化所提供相依性屬性的值。Returns a value that indicates whether serialization processes should serialize the value for the provided dependency property.

(繼承來源 DependencyObject)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)
VerifyAccess()

請強制執行可以存取這個 DispatcherObject 的呼叫執行緒。Enforces that the calling thread has access to this DispatcherObject.

(繼承來源 DispatcherObject)

明確介面實作

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.

適用於

另請參閱