EventTrigger.Actions 属性

定义

获取事件发生时要应用的操作的集合。Gets the collection of actions to apply when the event occurs.

public:
 property System::Windows::TriggerActionCollection ^ Actions { System::Windows::TriggerActionCollection ^ get(); };
public System.Windows.TriggerActionCollection Actions { get; }
member this.Actions : System.Windows.TriggerActionCollection
Public ReadOnly Property Actions As TriggerActionCollection

属性值

TriggerActionCollection

默认值为空集合。The default is an empty collection.

示例

此示例说明如何在样式中使用事件触发器来对的和事件进行动画处理 MouseEnter MouseLeave FrameworkElementThis example describes how to use event triggers in a style to animate the MouseEnter and MouseLeave events of a FrameworkElement. 如上所述,将 TriggerAction 子对象添加到 EventTrigger 对象会将其隐式添加到 TriggerActionCollection 对象的 EventTriggerAs mentioned above, adding a TriggerAction child to an EventTrigger object implicitly adds it to the TriggerActionCollection for the EventTrigger object. 因此,在此示例中, <EventTrigger.Actions> 是隐式的。Therefore, in this example, <EventTrigger.Actions> is implicit.

<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 不同 EventTrigger 的是,没有状态终止的概念,因此,一旦引发事件的条件不再为 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.

如果将 TriggerAction 子对象添加到对象中,则 EventTrigger 会将其隐式添加到 TriggerActionCollection 对象的 EventTriggerAdding a TriggerAction child to an EventTrigger object implicitly adds it to the TriggerActionCollection for the EventTrigger object.

备注

仅可通过所示的集合语法 (XAML) Extensible Application Markup Language 设置此属性,或者通过访问集合对象并使用它的各种方法(如 Add)来设置此属性。This property can only be set in Extensible Application Markup Language (XAML) via the collection syntax shown, or by accessing the collection object and using its various methods such as Add. 用于访问集合对象本身的属性是只读的,集合本身是可读写的。The property to access the collection object itself is read-only, the collection itself is read-write.

XAML 属性元素用法XAML Property Element Usage

<object>  
  <object.Actions>  
    OneOrMoreTriggerActions  
  </object.Actions>  
</object>  

XAML 值XAML Values

OneOrMoreTriggerActionsOneOrMoreTriggerActions
一个或多个 TriggerAction 对象。One or more TriggerAction objects.

适用于