EventTrigger EventTrigger EventTrigger EventTrigger Class

定義

代表套用一組動作以回應事件的觸發程序。Represents a trigger that applies a set of actions in response to an event.

public ref class EventTrigger : System::Windows::TriggerBase, System::Windows::Markup::IAddChild
[System.Windows.Markup.ContentProperty("Actions")]
public class EventTrigger : System.Windows.TriggerBase, System.Windows.Markup.IAddChild
type EventTrigger = class
    inherit TriggerBase
    interface IAddChild
Public Class EventTrigger
Inherits TriggerBase
Implements IAddChild
繼承
屬性
實作

範例

此範例示範如何在樣式中使用事件觸發程序,以動畫顯示MouseEnterMouseLeave事件的FrameworkElementThis example shows how to use event triggers in a style to animate the MouseEnter and MouseLeave events of a FrameworkElement. 在此範例中,Style已經TargetType設定為RectangleIn this example, the Style has the TargetType set to Rectangle. 因此,就不需要限定MouseEnterMouseLeave類別名稱的事件名稱。Therefore, there is no need to qualify the MouseEnter and MouseLeave event names with the class name.

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

備註

Trigger 物件具有SettersEnterActions,並ExitActions套用變更或根據特定屬性狀態的動作的屬性時EventTrigger物件一開始的一組Actions指定路由的事件發生時。Trigger objects have the Setters, EnterActions, and ExitActions properties that apply changes or actions based on the state of certain properties, while EventTrigger objects start a set of Actions when a specified routed event occurs. 例如,您可能想要EventTrigger來啟動一組動畫,當滑鼠指標位於特定使用者介面 (UI)user interface (UI)控制項。For example, you may want to use an EventTrigger to start a set of animations when the mouse pointer is over a certain 使用者介面 (UI)user interface (UI) control. 不同於TriggerEventTrigger並沒有終止狀態的概念,因此動作後引發事件的條件不再為 true,將無法復原。Unlike Trigger, EventTrigger has no concept of termination of state, so the action will not be undone once the condition that raised the event is no longer true.

請注意,當使用EventTrigger,您必須選擇不會干擾您的控制項繼承行為的事件。Note that when using an EventTrigger, you need to choose events that do not interfere with the inherent behavior of your control. 控制這類ButtonTextBox滑鼠點選之類的使用者輸入事件上執行特定動作和鍵盤事件。Controls such as Button or TextBox perform specific actions on user input events such as mouse clicks and keyboard events. 例如,如果您已設定樣式的按鈕,然後試著設定MouseDown事件做RoutedEventEventTrigger,則EventTrigger永遠不會取得套用,因為第一次取得處理事件的按鈕。For example, if you are styling a button and try to set the MouseDown event as the RoutedEvent of an EventTrigger, the EventTrigger never gets applied because the event first gets handled by the button. 相反地,您可以使用PreviewMouseDown事件或不同的事件。Instead, you can use the PreviewMouseDown event or a different event.

當使用資料繫結,如果您使用TargetUpdated事件,您必須設定NotifyOnTargetUpdated的值您Binding物件true引發事件。When using data binding, if you are using the TargetUpdated event, you must set the NotifyOnTargetUpdated value of your Binding object to true for the event to be raised.

新增TriggerAction子系EventTrigger物件會隱含地將它加入至TriggerActionCollectionEventTrigger物件。Adding a TriggerAction child to an EventTrigger object implicitly adds it to the TriggerActionCollection for the EventTrigger object.

建構函式

EventTrigger() EventTrigger() EventTrigger() EventTrigger()

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

EventTrigger(RoutedEvent) EventTrigger(RoutedEvent) EventTrigger(RoutedEvent) EventTrigger(RoutedEvent)

使用指定的事件,初始化 EventTrigger 類別的新執行個體。Initializes a new instance of the EventTrigger class with the specified event.

屬性

Actions Actions Actions Actions

取得事件發生時要套用的動作集合。Gets the collection of actions to apply when the event occurs.

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)
RoutedEvent RoutedEvent RoutedEvent RoutedEvent

取得或設定將啟動此觸發程序的 RoutedEventGets or sets the RoutedEvent that will activate this trigger.

SourceName SourceName SourceName SourceName

以啟動這個觸發程序的事件取得或設定物件的名稱。Gets or sets the name of the object with the event that activates this trigger. 只有項目觸發程序或範本觸發程序會使用它。This is only used by element triggers or template triggers.

方法

AddChild(Object) AddChild(Object) AddChild(Object) AddChild(Object)

將指定的物件加入至目前事件觸發程序的 Actions 集合。Adds the specified object to the Actions collection of the current event trigger.

AddText(String) AddText(String) AddText(String) AddText(String)

這個方法不受支援,而且會導致例外狀況。This method is not supported and results in an exception.

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)
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)
ShouldSerializeActions() ShouldSerializeActions() ShouldSerializeActions() ShouldSerializeActions()

傳回序列化程序是否應序列化這個類別執行個體上 Actions 屬性的有效值。Returns whether serialization processes should serialize the effective value of the Actions property on instances of this class.

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.

適用於

另請參閱