Condividi tramite


PopupMenu.ShowForSelectionAsync Metodo

Definizione

Overload

ShowForSelectionAsync(Rect)

Mostra il menu di scelta rapida sopra la selezione specificata.

ShowForSelectionAsync(Rect, Placement)

Mostra il menu di scelta rapida nel posizionamento preferito rispetto alla selezione specificata.

ShowForSelectionAsync(Rect)

Mostra il menu di scelta rapida sopra la selezione specificata.

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)

Parametri

selection
Rect

Le coordinate (in DIP) del rettangolo selezionato, relative alla finestra. Il menu di scelta rapida viene posizionato direttamente sopra e centrato su questo rettangolo in modo che la selezione non sia coperta.

Nota

Per VB, C#e C++, questa finestra è CoreWindow associata al thread che chiama il menu di scelta rapida.

Restituisce

Oggetto IUICommand che rappresenta il comando del menu di scelta rapida richiamato dall'utente, dopo il completamento della chiamata ShowForSelectionAsync.

Se non viene richiamato alcun comando, ShowForSelectionAsync restituisce Null.

Attributi

Esempio

Prima di poter visualizzare un menu di scelta rapida, è necessario aggiungere un listener eventi per l'evento oncontextmenu . Ad esempio, l'esempio di menu Contestuale ascolta l'evento su elementi HTML specifici e quindi chiama la scenario1AttachmentHandler funzione.

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");
    }
});

Inoltre, l'esempio di menu di scelta rapida usa due funzioni helper (getSelectionRect e getclientCoordinates) per impostare le coordinate per il rettangolo di selezione.

// 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
    };
}

Commenti

È possibile visualizzare esempi di codice completi che illustrano come creare e personalizzare i menu di scelta rapida nell'esempio di menu di scelta rapida.

Vedi anche

Si applica a

ShowForSelectionAsync(Rect, Placement)

Mostra il menu di scelta rapida nel posizionamento preferito rispetto alla selezione specificata.

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)

Parametri

selection
Rect

Le coordinate (in DIP) del rettangolo selezionato, relative alla finestra.

Nota

Per VB, C#e C++, questa finestra è CoreWindow associata al thread che chiama il menu di scelta rapida.

preferredPlacement
Placement

Posizione preferita del menu di scelta rapida rispetto al rettangolo di selezione.

Il menu di scelta rapida è posizionato nella posizione preferitaPlacement se il menu si adatta alla finestra e non copre la selezione. Se il menu di scelta rapida non rientra nella posizione preferita, viene utilizzata un'altra posizione che non copre la selezione. Se il menu di scelta rapida non si adatta altrove, viene utilizzata una posizione che copre parzialmente o completamente la selezione.

Restituisce

Oggetto IUICommand che rappresenta il comando del menu di scelta rapida richiamato dall'utente, dopo il completamento della chiamata ShowForSelectionAsync .

Se non viene richiamato alcun comando, ShowForSelectionAsync restituisce Null.

Attributi

Esempio

Prima di poter visualizzare un menu di scelta rapida, è necessario aggiungere un listener eventi per l'evento oncontextmenu . Ad esempio, l'esempio di menu Contestuale ascolta l'evento su elementi HTML specifici e quindi chiama la scenario1AttachmentHandler funzione.

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
    };
}

Commenti

È possibile visualizzare esempi di codice completi che illustrano come creare e personalizzare i menu di scelta rapida nell'esempio di menu di scelta rapida.

Vedi anche

Si applica a