PopupMenu.ShowForSelectionAsync 메서드

정의

오버로드

ShowForSelectionAsync(Rect)

지정된 선택 영역 위의 상황에 맞는 메뉴를 표시합니다.

ShowForSelectionAsync(Rect, Placement)

지정한 선택 영역을 기준으로 기본 배치의 상황에 맞는 메뉴를 표시합니다.

ShowForSelectionAsync(Rect)

지정된 선택 영역 위의 상황에 맞는 메뉴를 표시합니다.

public:
 virtual IAsyncOperation<IUICommand ^> ^ ShowForSelectionAsync(Rect selection) = ShowForSelectionAsync;
/// [Windows.Foundation.Metadata.Overload("ShowAsyncWithRect")]
IAsyncOperation<IUICommand> ShowForSelectionAsync(Rect const& selection);
[Windows.Foundation.Metadata.Overload("ShowAsyncWithRect")]
public IAsyncOperation<IUICommand> ShowForSelectionAsync(Rect selection);
function showForSelectionAsync(selection)
Public Function ShowForSelectionAsync (selection As Rect) As IAsyncOperation(Of IUICommand)

매개 변수

selection
Rect

창에 상대적인 선택한 사각형의 좌표(DIP)입니다. 상황에 맞는 메뉴는 바로 위에 배치되고 선택 영역이 적용되지 않도록 이 사각형의 가운데에 배치됩니다.

참고

VB, C#및 C++의 경우 이 창은 상황에 맞는 메뉴를 호출하는 스레드와 연결된 CoreWindow 입니다.

반환

ShowForSelectionAsync 호출이 완료된 후 사용자가 호출한 상황에 맞는 메뉴 명령을 나타내는 IUICommand 개체입니다.

명령이 호출되지 않으면 ShowForSelectionAsync는 null을 반환합니다.

특성

예제

상황에 맞는 메뉴를 표시하려면 먼저 oncontextmenu 이벤트에 대한 이벤트 수신기를 추가해야 합니다. 예를 들어 상황에 맞는 메뉴 샘플 은 특정 HTML 요소에서 이벤트를 수신 대기한 다음 함수를 호출합니다 scenario1AttachmentHandler .

document.getElementById("attachment").addEventListener("contextmenu", attachmentHandler, false);
// We don't want to obscure content, so pass in the position representing the selection area.
menu.showForSelectionAsync(clientToWinRTRect(document.selection.createRange().getBoundingClientRect())).then(function (invokedCommand) {
    if (invokedCommand !== null) {
        switch (invokedCommand.id) {
            case 1: // Copy
                var selectedText = window.getSelection();
                copyTextToClipboard(selectedText);
                var message = "'Copy' button clicked and '" + /*@static_cast(String)*/selectedText + "' copied to clipboard";
                WinJS.log && WinJS.log(message, "sample", "status");
                break;
            case 2: // Highlight
                // Add command handler code here.
                WinJS.log && WinJS.log("'Highlight' button clicked", "sample", "status");
                break;
            case 3: // Look up
                // Add command handler code here.
                WinJS.log && WinJS.log("'Look up' button clicked", "sample", "status");
                break;
            default:
                break;
        }
    } else {
        // The command is null if no command was invoked.
        WinJS.log && WinJS.log("Context menu dismissed", "sample", "status");
    }
});

또한 상황에 맞는 메뉴 샘플 에서는 두 개의 도우미 함수(getSelectionRectgetclientCoordinates)를 사용하여 선택 사각형의 좌표를 설정합니다.

// Converts from client to WinRT coordinates, which take scale factor into consideration.
function clientToWinRTRect(rect) {
    var zoomFactor = document.documentElement.msContentZoomFactor;
    return {
        x: (rect.left + document.documentElement.scrollLeft - window.pageXOffset) * zoomFactor,
        y: (rect.top + document.documentElement.scrollTop - window.pageYOffset) * zoomFactor,
        width: rect.width * zoomFactor,
        height: rect.height * zoomFactor
    };
}

설명

상황에 맞는 메뉴 샘플에서 상황에 맞는 메뉴를 만들고 사용자 지정하는 방법을 보여 주는 전체 코드 예제를 볼 수 있습니다.

추가 정보

적용 대상

ShowForSelectionAsync(Rect, Placement)

지정한 선택 영역을 기준으로 기본 배치의 상황에 맞는 메뉴를 표시합니다.

public:
 virtual IAsyncOperation<IUICommand ^> ^ ShowForSelectionAsync(Rect selection, Placement preferredPlacement) = ShowForSelectionAsync;
/// [Windows.Foundation.Metadata.Overload("ShowAsyncWithRectAndPlacement")]
IAsyncOperation<IUICommand> ShowForSelectionAsync(Rect const& selection, Placement const& preferredPlacement);
[Windows.Foundation.Metadata.Overload("ShowAsyncWithRectAndPlacement")]
public IAsyncOperation<IUICommand> ShowForSelectionAsync(Rect selection, Placement preferredPlacement);
function showForSelectionAsync(selection, preferredPlacement)
Public Function ShowForSelectionAsync (selection As Rect, preferredPlacement As Placement) As IAsyncOperation(Of IUICommand)

매개 변수

selection
Rect

창에 상대적인 선택한 사각형의 좌표(DIP)입니다.

참고

VB, C#및 C++의 경우 이 창은 상황에 맞는 메뉴를 호출하는 스레드와 연결된 CoreWindow 입니다.

preferredPlacement
Placement

선택 사각형을 기준으로 상황에 맞는 메뉴의 기본 배치입니다.

메뉴가 창에 맞고 선택 영역을 다루지 않는 경우 상황에 맞는 메뉴가 preferredPlacement 에 배치됩니다. 상황에 맞는 메뉴가 기본 배치에 맞지 않으면 선택 영역을 다루지 않는 다른 배치가 사용됩니다. 상황에 맞는 메뉴가 다른 위치에 맞지 않으면 선택 영역을 부분적으로 또는 완전히 포함하는 배치가 사용됩니다.

반환

ShowForSelectionAsync 호출이 완료된 후 사용자가 호출한 상황에 맞는 메뉴 명령을 나타내는 IUICommand 개체입니다.

명령이 호출되지 않으면 ShowForSelectionAsyncnull을 반환합니다.

특성

예제

상황에 맞는 메뉴를 표시하려면 먼저 oncontextmenu 이벤트에 대한 이벤트 수신기를 추가해야 합니다. 예를 들어 상황에 맞는 메뉴 샘플 은 특정 HTML 요소에서 이벤트를 수신 대기한 다음 함수를 호출합니다 scenario1AttachmentHandler .

document.getElementById("attachment").addEventListener("contextmenu", attachmentHandler, false);
// Converts from client to WinRT coordinates, which take scale factor into consideration.
function clientToWinRTRect(rect) {
    var zoomFactor = document.documentElement.msContentZoomFactor;
    return {
        x: (rect.left + document.documentElement.scrollLeft - window.pageXOffset) * zoomFactor,
        y: (rect.top + document.documentElement.scrollTop - window.pageYOffset) * zoomFactor,
        width: rect.width * zoomFactor,
        height: rect.height * zoomFactor
    };
}

설명

상황에 맞는 메뉴 샘플에서 상황에 맞는 메뉴를 만들고 사용자 지정하는 방법을 보여 주는 전체 코드 예제를 볼 수 있습니다.

추가 정보

적용 대상