Stylus.StylusEnter Stylus.StylusEnter Stylus.StylusEnter Attached Event

定义

触笔光标进入元素的边界时发生。Occurs when the stylus cursor enters the bounds of an element.

see AddStylusEnterHandler, and RemoveStylusEnterHandler
see AddStylusEnterHandler, and RemoveStylusEnterHandler
see AddStylusEnterHandler, and RemoveStylusEnterHandler

示例

下面的示例演示如何在触笔光标进入和Button离开边界时更改的颜色。The following example demonstrates how to change the color of a Button when the stylus cursor enters and leaves its bounds. 此示例Button假设有一个被调用button1 StylusEnter的, 并且和StylusLeave事件已连接到事件处理程序。This example assumes that there is a Button called button1 and that the StylusEnter and StylusLeave events are connected to the event handlers.

Brush originalColor;

void button1_StylusLeave(object sender, StylusEventArgs e)
{
    button1.Background = originalColor;
}

void button1_StylusEnter(object sender, StylusEventArgs e)
{
    originalColor = button1.Background; 
    button1.Background = Brushes.Gray;
}
Private originalColor As Brush

Private Sub button1_StylusLeave(ByVal sender As Object, ByVal e As StylusEventArgs) _
    Handles button1.StylusLeave

    button1.Background = originalColor

End Sub

Private Sub button1_StylusEnter(ByVal sender As Object, ByVal e As StylusEventArgs) _
    Handles button1.StylusEnter

    originalColor = button1.Background
    button1.Background = Brushes.Gray

End Sub

注解

这是一个附加事件。This is an attached event. WPFWPF将附加事件作为路由事件实现。implements attached events as routed events. 附加事件本质上是一种XAMLXAML语言概念, 它用于引用处理的事件, 这些事件本身不是定义事件。An attached event is, fundamentally, a XAMLXAML language concept used to reference events that are handled on objects that do not, themselves, define events. WPFWPF进一步扩展了附加事件的功能, 从而允许它遍历路由。further expands an attached event's capabilities, allowing it to traverse a route. 附加事件在代码中没有直接处理语法;若要在代码中附加路由事件的处理程序, 请使用指定的 Add * 处理程序方法。Attached events do not have a direct handling syntax in code; to attach handlers for a routed event in code, use a designated Add*Handler method. 有关详细信息, 请参阅附加事件概述For details, see Attached Events Overview.

路由事件信息Routed Event Information

标识符字段Identifier field StylusEnterEvent
路由策略Routing strategy 直接Direct
委托Delegate StylusEventHandler

适用于

另请参阅