EventTrigger.RoutedEvent 属性

定义

获取或设置将激活该触发器的 RoutedEventGets or sets the RoutedEvent that will activate this trigger.

public:
 property System::Windows::RoutedEvent ^ RoutedEvent { System::Windows::RoutedEvent ^ get(); void set(System::Windows::RoutedEvent ^ value); };
public System.Windows.RoutedEvent RoutedEvent { get; set; }
member this.RoutedEvent : System.Windows.RoutedEvent with get, set
Public Property RoutedEvent As RoutedEvent

属性值

默认值为 nullThe default value is null.

异常

RoutedEvent 属性不能为 null。The RoutedEvent property cannot be null.

示例

此示例演示如何在样式中使用事件触发器来对的MouseEnterMouseLeave事件FrameworkElement进行动画处理。This 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>

注解

EventTriggers 在指定的路由事件发生时应用一组操作。EventTriggers apply a set of actions when the specified routed event occurs. 例如, 你可能想要在鼠标EventTrigger指针位于特定用户界面 (UI)user interface (UI)控件上时使用来启动一组动画。For example, you may want to use EventTriggers to start a set of animations when the mouse pointer is over a certain 用户界面 (UI)user interface (UI) control.

如果包含此EventTrigger TargetType属性的模板或样式未指定属性, 则需要使用ClassName.EventName语法来为事件名称提供类名的质量。If the template or style that contains this EventTrigger does not have the TargetType property specified, then you need to quality the event name with the class name using the ClassName.EventName syntax.

EventTrigger对象无法处理已经存在的Handled事件。EventTrigger objects cannot handle events that have already been Handled. 控件 ( Button例如或TextBox ) 对用户输入事件执行特定操作, 例如鼠标单击和键盘事件。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是事件, 则必须将Binding对象的NotifyOnTargetUpdated值设置为 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.

适用于

另请参阅