EventTrigger 類別

定義

代表套用一組動作以回應事件的觸發程序。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
繼承
屬性
實作

範例

這個範例會示範如何使用樣式中的事件觸發程式, 以MouseEnter動畫MouseLeave顯示的和FrameworkElement事件。This example shows how to use event triggers in a style to animate the MouseEnter and MouseLeave events of a FrameworkElement. 在此範例中, StyleTargetType已將設Rectangle為。In 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>

備註

TriggerSetters物件具有ActionsEnterActionsExitActions屬性, 可根據特定屬性的狀態套用變更或動作, 而EventTrigger物件則會在指定的路由事件發生時啟動一組。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並嘗試將事件設RoutedEvent為的EventTrigger, 則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使用事件, 則必須NotifyOnTargetUpdatedBinding物件的值設定為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.

將子系加入TriggerActionCollection物件中時, 會隱含地將它加入至物件的。EventTrigger EventTrigger TriggerActionAdding a TriggerAction child to an EventTrigger object implicitly adds it to the TriggerActionCollection for the EventTrigger object.

建構函式

EventTrigger()

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

EventTrigger(RoutedEvent)

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

屬性

Actions

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

DependencyObjectType

取得包裝此執行個體之 CLRCLR 型別的 DependencyObjectTypeGets 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)
RoutedEvent

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

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)

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

AddText(String)

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

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. 完成方式是叫用存在於呼叫 DependencyObject 之相依性屬性的屬性中繼資料中所指定的任何 CoerceValueCallback 函式。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)
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)
ShouldSerializeActions()

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

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.

適用於

另請參閱