Stylus.StylusButtonDown Stylus.StylusButtonDown Stylus.StylusButtonDown Attached Event

定义

在用户按下触笔上的其中一个按钮时发生。Occurs when the user presses one of the buttons on the stylus.

see AddStylusButtonDownHandler, and RemoveStylusButtonDownHandler
see AddStylusButtonDownHandler, and RemoveStylusButtonDownHandler
see AddStylusButtonDownHandler, and RemoveStylusButtonDownHandler

示例

下面的示例演示如何在用户按下触笔上的圆筒按钮时显示快捷菜单。The following example demonstrates how to show a shortcut menu when the user presses the barrel button on a stylus. 此示例假定存在一个TextBoxtextBox1为的和一个ContextMenu调用textBoxContextMenu的, 并且StylusButtonDown该事件已连接到事件处理程序。This example assumes that there is a TextBox called textBox1, and a ContextMenu called textBoxContextMenu, and that the StylusButtonDown event is connected to the event handler.

// Show or hide a shortcut menu when the user clicks the barrel button.
void textbox1_StylusButtonDown(object sender, StylusButtonEventArgs e)
{
    if (e.StylusButton.Guid != StylusPointProperties.BarrelButton.Id)
    {
        return;
    }

    if (textbox1.ContextMenu == null)
    {
        textbox1.ContextMenu = textBoxContextMenu;
    }
    else
    {
        textbox1.ContextMenu = null;
    }
}
' Show or hide a shortcut menu when the user clicks the barrel button.
Private Sub textbox1_StylusButtonDown(ByVal sender As Object, ByVal e As StylusButtonEventArgs) _
    Handles textbox1.StylusButtonDown

    If e.StylusButton.Guid <> StylusPointProperties.BarrelButton.Id Then
        Return
    End If

    If textbox1.ContextMenu Is Nothing Then
        textbox1.ContextMenu = textBoxContextMenu
    Else
        textbox1.ContextMenu = Nothing
    End If

End Sub 'textbox1_StylusButtonDown

注解

这是一个附加事件。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 StylusButtonDownEvent
路由策略Routing strategy 冒泡Bubbling
委托Delegate StylusButtonEventHandler

适用于

另请参阅