UIElement.PointerPressed 이벤트

정의

포인터 디바이스가 이 요소 내에서 Press 작업을 시작할 때 발생합니다.

public:
 virtual event PointerEventHandler ^ PointerPressed;
// Register
event_token PointerPressed(PointerEventHandler const& handler) const;

// Revoke with event_token
void PointerPressed(event_token const* cookie) const;

// Revoke with event_revoker
UIElement::PointerPressed_revoker PointerPressed(auto_revoke_t, PointerEventHandler const& handler) const;
public event PointerEventHandler PointerPressed;
function onPointerPressed(eventArgs) { /* Your code */ }
uIElement.addEventListener("pointerpressed", onPointerPressed);
uIElement.removeEventListener("pointerpressed", onPointerPressed);
- or -
uIElement.onpointerpressed = onPointerPressed;
Public Custom Event PointerPressed As PointerEventHandler 
<uiElement PointerPressed="eventhandler"/>

이벤트 유형

설명

터치, 마우스 및 펜/스타일러스 상호 작용은 UWP 앱에서 포인터 입력으로 수신, 처리 및 관리됩니다. 이러한 상호 작용은 PointerPressed 이벤트를 생성할 수 있습니다. 자세한 내용은 포인터 입력 처리를 참조하세요. 포인터 이벤트는 여러 포인터 및 해당 관계에 관심이 있거나 정확한 좌표 위치와 같은 각 포인터의 세부 정보를 검사하는 시나리오를 위한 것입니다. 그렇지 않으면 Tapped와 같은 제스처 이벤트를 처리하는 것이 좋습니다.

PointerEventHandler를 기반으로 하는 처리기를 사용하여 이 이벤트를 처리합니다.

마우스 입력이 먼저 감지되면 마우스 입력이 할당된 단일 포인터와 연결됩니다. 마우스 단추(왼쪽, 휠 또는 오른쪽)를 클릭하면 PointerPressed 이벤트를 통해 포인터와 해당 단추 간의 보조 연결이 만들어집니다. PointerReleased 이벤트는 해당하는 동일한 마우스 단추를 해제한 경우에만 발생합니다(이 이벤트가 완료될 때까지는 다른 단추를 이 포인터와 연결할 수 없음). 이 독점적인 연결 때문에 다른 마우스 단추 클릭은 PointerMoved 이벤트를 통해 라우트됩니다. 다음 예제와 같이 이 이벤트를 처리할 때 마우스 단추 상태를 테스트할 수 있습니다.

private void Target_PointerMoved(object sender, PointerRoutedEventArgs e)
{
    Windows.UI.Xaml.Input.Pointer ptr = e.Pointer;

    // Multiple, simultaneous mouse button inputs are processed here.
    // Mouse input is associated with a single pointer assigned when 
    // mouse input is first detected. 
    // Clicking additional mouse buttons (left, wheel, or right) during 
    // the interaction creates secondary associations between those buttons 
    // and the pointer through the pointer pressed event. 
    // The pointer released event is fired only when the last mouse button 
    // associated with the interaction (not necessarily the initial button) 
    // is released. 
    // Because of this exclusive association, other mouse button clicks are 
    // routed through the pointer move event.          
    if (ptr.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse)
    {
        // To get mouse state, we need extended pointer details.
        // We get the pointer info through the getCurrentPoint method
        // of the event argument. 
        Windows.UI.Input.PointerPoint ptrPt = e.GetCurrentPoint(Target);
        if (ptrPt.Properties.IsLeftButtonPressed)
        {
            eventLog.Text += "\nLeft button: " + ptrPt.PointerId;
        }
        if (ptrPt.Properties.IsMiddleButtonPressed)
        {
            eventLog.Text += "\nWheel button: " + ptrPt.PointerId;
        }
        if (ptrPt.Properties.IsRightButtonPressed)
        {
            eventLog.Text += "\nRight button: " + ptrPt.PointerId;
        }
    }

    // Prevent most handlers along the event route from handling the same event again.
    e.Handled = true;

    // Display pointer details.
    updateInfoPop(e);
}
private void Target_PointerMoved(object sender, PointerRoutedEventArgs e)
{
    Windows.UI.Xaml.Input.Pointer ptr = e.Pointer;

    // Multiple, simultaneous mouse button inputs are processed here.
    // Mouse input is associated with a single pointer assigned when 
    // mouse input is first detected. 
    // Clicking additional mouse buttons (left, wheel, or right) during 
    // the interaction creates secondary associations between those buttons 
    // and the pointer through the pointer pressed event. 
    // The pointer released event is fired only when the last mouse button 
    // associated with the interaction (not necessarily the initial button) 
    // is released. 
    // Because of this exclusive association, other mouse button clicks are 
    // routed through the pointer move event.          
    if (ptr.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse)
    {
        // To get mouse state, we need extended pointer details.
        // We get the pointer info through the getCurrentPoint method
        // of the event argument. 
        Windows.UI.Input.PointerPoint ptrPt = e.GetCurrentPoint(Target);
        if (ptrPt.Properties.IsLeftButtonPressed)
        {
            eventLog.Text += "\nLeft button: " + ptrPt.PointerId;
        }
        if (ptrPt.Properties.IsMiddleButtonPressed)
        {
            eventLog.Text += "\nWheel button: " + ptrPt.PointerId;
        }
        if (ptrPt.Properties.IsRightButtonPressed)
        {
            eventLog.Text += "\nRight button: " + ptrPt.PointerId;
        }
    }

    // Prevent most handlers along the event route from handling the same event again.
    e.Handled = true;

    // Display pointer details.
    updateInfoPop(e);
}

마우스 입력 디바이스의 포인터 이벤트는 일반적으로 앱 수명 동안 이벤트 세부 정보에 동일한 PointerId 를 갖습니다.

PointerPressed는 라우트된 이벤트입니다. 라우트된 이벤트 개념에 대한 자세한 내용은 이벤트 및 라우트된 이벤트 개요를 참조하세요.

터치 동작의 경우와 터치 동작의 결과인 조작 관련 또는 조작 이벤트의 경우에도 이벤트 원본이 되거나 터치 동작과 연관된 이벤트를 실행하려면 요소의 적중 횟수 테스트가 보여야 합니다. UIElement.Visibility표시되어야 합니다. 파생 형식의 다른 속성도 적중 테스트 표시 유형에 영향을 미칩니다. 자세한 내용은 이벤트 및 라우트된 이벤트 개요를 참조하세요.

PointerPressed는 이벤트에 대한 이벤트 데이터가 처리됨으로 표시된 경우에도 호출될 경로에 이벤트 처리기를 연결하는 기능을 지원 합니다. AddHandler를 참조하세요.

특정 Windows 런타임 컨트롤에는 PointerPressed 입력 이벤트에 대한 클래스 기반 처리가 있을 수 있습니다. 이 경우 컨트롤에 OnPointerPressed 메서드에 대한 재정의가 있는 것일 수 있습니다. 일반적으로 이벤트는 클래스 처리기에 의해 처리된 것으로 표시되며 PointerPressed 이벤트는 해당 컨트롤의 사용자 코드 처리기에서 처리하기 위해 발생하지 않습니다. 예를 들어 ButtonBase 에는 PointerPressed를 처리하고 대신 Click을 발생시키는 클래스 처리가 있습니다. 이벤트에 대한 클래스 기반 처리의 작동 방식에 대한 자세한 내용은 이벤트 및 라우트된 이벤트 개요를 참조하세요.

컨트롤에는 이벤트와 독립적으로 실행되는 PointerDownThemeAnimation 성격 애니메이션이 있을 수도 있습니다.

포인터 캡처

PointerPressed는 포인터를 캡처할 때 시작 이벤트로 사용되기도 하므로 포인터가 아래로 유지되는 한 추가 포인터 관련 이벤트가 모두 특정 요소에 의해 캡처됩니다. 포인터를 캡처하려면 캡처를 유지해야 하는 특정 UI 요소에서 CapturePointer 메서드를 호출합니다. 이 작업은 일반적으로 PointerPressed 이벤트 처리기 내에서 수행되며 이벤트의 보낸 사람에서 CapturePointer를 호출합니다. 포인터를 캡처하는 방법 및 포인터를 캡처하려는 이유에 대한 자세한 내용은 CapturePointer를 참조하세요.

PointerPressed 및 제스처 이벤트 또는 조작 이벤트

처음에 PointerPressed 이벤트를 발생시키는 사용자 작업은 입력 디바이스가 마우스가 아닌 한 홀드 제스처를 나타내는 Holding 이벤트가 발생할 수 있습니다. PointerPressed가 발생하는 요소에 기본값이 아닌 ManipulationMode 값이 있는 경우 작업으로 인해 ManipulationStarted와 같은 다양한 조작 이벤트가 발생할 수도 있습니다. 자세한 내용은 포인터 입력 처리의 "조작 이벤트 사용" 섹션을 참조하세요.

PointerPressed가 실행되면 Holding 이외의 제스처 이벤트가 이벤트를 발생하기 전에 포인터가 해제되기를 기다리고 있기 때문에 Tapped와 같은 제스처 이벤트가 아직 실행되지 않습니다.

앱의 사용자 상호 작용에 대한 일반적인 디자인 규칙으로 상호 작용에 대해 처리할 수 있는 컨트롤 관련 이벤트 또는 적절한 제스처 이벤트가 있는지 확인해야 합니다. 예를 들어 컨트롤이 Button인 경우 해당 컨트롤에는 사용자가 단추의 작업을 호출할 때 특별히 의도한 Click 이벤트가 있습니다. 또는 요소가 단추가 아니지만 요소의 기본 작업에 대한 및 이벤트를 처리하는 경우 Tapped를 처리합니다.

IsTapEnabled와 같은 속성을 설정하여 개별 요소에서 제스처 이벤트를 특별히 사용하지 않도록 설정할 수 있습니다. 조작을 처리하는 경우 제스처 이벤트를 사용하지 않도록 설정할 수 있지만 포인터 이벤트를 처리하는 경우 일반적으로 제스처 이벤트를 사용하지 않도록 설정할 필요가 없습니다. 포인터 이벤트는 특별히 사용하지 않도록 설정할 수 없지만 처리하지 않도록 선택할 수 있습니다.

PointerPressed 및 PointerReleased

PointerReleased 대신 다른 이벤트는 작업의 끝에서 발생할 수 있습니다(예: PointerCanceled 또는 PointerCaptureLost). PointerPressed 및 PointerReleased 이벤트는 항상 쌍으로 발생하지 않습니다. 제대로 작동하려면 앱이 언론 작업에 대한 결론을 나타내는 모든 이벤트를 수신 대기하고 처리해야 합니다. PointerReleased 발생이 발생하지 않는 몇 가지 이유는 다음과 같습니다.

  • 특정 하드웨어가 터치 작업을 처리하는 방법 및 누름 작업의 차이점
  • 다른 포인터에서 프로그래밍 포인터 캡처
  • 디스플레이 영역의 관계를 변경하는 사용자 작업(예: 해상도 변경 또는 설정 모니터링)
  • 이전 터치 동작과 동일한 표면을 터치하는 스타일러스와 같은 입력 상호 작용

적용 대상

추가 정보