Trigger Trigger Trigger Trigger Class

定義

表示觸發程序,這個觸發程序 (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
繼承
屬性
實作

範例

下列範例會顯示名Style為的Button控制項可用的。The following example shows a named Style available to Button controls. Style Foreground定義當屬性IsPressed為時, 會變更true按鈕屬性的元素。TriggerThe 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定義對應至使用者動作的屬性, 例如當使用者將游標IsMouseOver UIElement停留在或的對應true IsMouseOver屬性ContentElement上時設定為的屬性。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. 在屬性值中代表使用者動作, 連同專案, 可TriggerWPFWPF樣式根據這些使用者動作來變更屬性值, 而這一切都是從標記內完成。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. 觸發程式已針對預期會變更並回到原始狀態的暫時性狀態優化, IsPressed例如 on ButtonIsSelected on ListBoxItemTriggers 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.

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

物件的Setters屬性只能包含物件。Setter TriggerThe Setters property of a Trigger object can only consist of Setter objects. 將子系加入SetterBaseCollection物件中時, 會隱含地將它加入至物件的。Trigger Trigger SetterAdding 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() Trigger() Trigger()

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

屬性

DependencyObjectType DependencyObjectType DependencyObjectType DependencyObjectType

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

(Inherited from DependencyObject)
Dispatcher Dispatcher Dispatcher Dispatcher

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

(Inherited from DispatcherObject)
EnterActions EnterActions EnterActions 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.

(Inherited from TriggerBase)
ExitActions ExitActions ExitActions 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.

(Inherited from TriggerBase)
IsSealed IsSealed IsSealed IsSealed

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

(Inherited from DependencyObject)
Property Property Property 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 Setters Setters Setters

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

SourceName SourceName SourceName SourceName

取得或設定物件名稱,這個物件具有會套用相關聯之 setter 的屬性。Gets or sets the name of the object with the property that causes the associated setters to be applied.

Value Value Value Value

取得或設定要與項目之屬性值相比較的值。Gets or sets the value to be compared with the property value of the element. 這個比較是參考相等檢查。The comparison is a reference equality check.

方法

CheckAccess() CheckAccess() CheckAccess() CheckAccess()

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

(Inherited from DispatcherObject)
ClearValue(DependencyProperty) ClearValue(DependencyProperty) ClearValue(DependencyProperty) ClearValue(DependencyProperty)

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

(Inherited from DependencyObject)
ClearValue(DependencyPropertyKey) ClearValue(DependencyPropertyKey) ClearValue(DependencyPropertyKey) ClearValue(DependencyPropertyKey)

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

(Inherited from DependencyObject)
CoerceValue(DependencyProperty) CoerceValue(DependencyProperty) CoerceValue(DependencyProperty) 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.

(Inherited from DependencyObject)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from DependencyObject)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from DependencyObject)
GetLocalValueEnumerator() GetLocalValueEnumerator() GetLocalValueEnumerator() GetLocalValueEnumerator()

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

(Inherited from DependencyObject)
GetType() GetType() GetType() GetType()

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

(Inherited from Object)
GetValue(DependencyProperty) GetValue(DependencyProperty) GetValue(DependencyProperty) GetValue(DependencyProperty)

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

(Inherited from DependencyObject)
InvalidateProperty(DependencyProperty) InvalidateProperty(DependencyProperty) InvalidateProperty(DependencyProperty) InvalidateProperty(DependencyProperty)

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

(Inherited from DependencyObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
OnPropertyChanged(DependencyPropertyChangedEventArgs) OnPropertyChanged(DependencyPropertyChangedEventArgs) OnPropertyChanged(DependencyPropertyChangedEventArgs) 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.

(Inherited from DependencyObject)
ReadLocalValue(DependencyProperty) ReadLocalValue(DependencyProperty) ReadLocalValue(DependencyProperty) ReadLocalValue(DependencyProperty)

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

(Inherited from DependencyObject)
ReceiveTypeConverter(Object, XamlSetTypeConverterEventArgs) ReceiveTypeConverter(Object, XamlSetTypeConverterEventArgs) ReceiveTypeConverter(Object, XamlSetTypeConverterEventArgs) ReceiveTypeConverter(Object, XamlSetTypeConverterEventArgs)

處理型別轉換子對 Trigger 物件的屬性提供值的情況。Handles cases where a type converter provides a value for a property of a Trigger object.

SetCurrentValue(DependencyProperty, Object) SetCurrentValue(DependencyProperty, Object) SetCurrentValue(DependencyProperty, Object) SetCurrentValue(DependencyProperty, Object)

設定相依性屬性的值,而不需要變更其值來源。Sets the value of a dependency property without changing its value source.

(Inherited from DependencyObject)
SetValue(DependencyProperty, Object) SetValue(DependencyProperty, Object) SetValue(DependencyProperty, Object) SetValue(DependencyProperty, Object)

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

(Inherited from DependencyObject)
SetValue(DependencyPropertyKey, Object) SetValue(DependencyPropertyKey, Object) SetValue(DependencyPropertyKey, Object) SetValue(DependencyPropertyKey, Object)

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

(Inherited from DependencyObject)
ShouldSerializeProperty(DependencyProperty) ShouldSerializeProperty(DependencyProperty) ShouldSerializeProperty(DependencyProperty) ShouldSerializeProperty(DependencyProperty)

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

(Inherited from DependencyObject)
ToString() ToString() ToString() ToString()

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

(Inherited from Object)
VerifyAccess() VerifyAccess() VerifyAccess() VerifyAccess()

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

(Inherited from DispatcherObject)

明確介面實作

IAddChild.AddChild(Object) IAddChild.AddChild(Object) IAddChild.AddChild(Object) IAddChild.AddChild(Object)

加入子物件。Adds a child object.

IAddChild.AddText(String) IAddChild.AddText(String) IAddChild.AddText(String) IAddChild.AddText(String)

將節點的文字內容加入物件中。Adds the text content of a node to the object.

ISupportInitialize.BeginInit() ISupportInitialize.BeginInit() ISupportInitialize.BeginInit() ISupportInitialize.BeginInit()

表示物件正在啟動初始設定。Signals the object that initialization is starting.

ISupportInitialize.EndInit() ISupportInitialize.EndInit() ISupportInitialize.EndInit() ISupportInitialize.EndInit()

表示物件已完成初始設定。Signals the object that initialization is complete.

適用於

另請參閱