Partilhar via


Classe MenuAction

Um item de menu de contexto que representa uma ação a ser tomada no designer.

Namespace:  Microsoft.Windows.Design.Interaction
Assembly:  Microsoft.Windows.Design.Extensibility (em Microsoft.Windows.Design.Extensibility.dll)

Sintaxe

Public Class MenuAction _
    Inherits MenuBase

Dim instance As MenuAction
public class MenuAction : MenuBase
public ref class MenuAction : public MenuBase
public class MenuAction extends MenuBase

Comentários

Use o MenuAction classe para definir um item de menu de contexto na WPF Designer. 

Para mostrar itens de menu de contexto, herdam o ContextMenuProvider classe e criar MenuAction itens e um associado MenuGroup. Esses objetos menu geralmente são criados no construtor de uma classe derivada de PrimarySelectionContextMenuProvider, que mostra o menu de contexto na seleção principal.

Implementar a lógica para o seu MenuAction no Execute manipulador de eventos.

The MenuAction classe é compatível com o sistema de comando do WPF. Use o Command propriedade para invocar o MenuAction programaticamente, em vez de através da interface do usuário.

Exemplos

O seguinte código exemplo mostra como conjunto até dois MenuAction itens que conjunto o Background propriedade de um controle em time de design. Para obter mais informações, consulte Demonstra Passo a passo: Criando um MenuAction.

Private setBackgroundToBlueMenuAction As MenuAction
Private clearBackgroundMenuAction As MenuAction


...


' The provider's constructor sets up the MenuAction objects 
' and the the MenuGroup which holds them.
Public Sub New()

    ' Set up the MenuAction which sets the control's 
    ' background to Blue.
    setBackgroundToBlueMenuAction = New MenuAction("Blue")
    setBackgroundToBlueMenuAction.Checkable = True
    AddHandler setBackgroundToBlueMenuAction.Execute, AddressOf SetBackgroundToBlue_Execute

    ' Set up the MenuAction which sets the control's 
    ' background to its default value.
    clearBackgroundMenuAction = New MenuAction("Cleared")
    clearBackgroundMenuAction.Checkable = True
    AddHandler clearBackgroundMenuAction.Execute, AddressOf ClearBackground_Execute

    ' Set up the MenuGroup which holds the MenuAction items.
    Dim backgroundFlyoutGroup As New MenuGroup("SetBackgroundsGroup", "Set Background")

    ' If HasDropDown is false, the group appears inline, 
    ' instead of as a flyout. Set to true.
    backgroundFlyoutGroup.HasDropDown = True
    backgroundFlyoutGroup.Items.Add(setBackgroundToBlueMenuAction)
    backgroundFlyoutGroup.Items.Add(clearBackgroundMenuAction)
    Me.Items.Add(backgroundFlyoutGroup)

    ' The UpdateItemStatus event is raised immediately before 
    ' this provider shows its tabs, which provides the opportunity 
    ' to set states.
    AddHandler UpdateItemStatus, AddressOf CustomContextMenuProvider_UpdateItemStatus

End Sub
private MenuAction setBackgroundToBlueMenuAction;
private MenuAction clearBackgroundMenuAction;


...


// The provider's constructor sets up the MenuAction objects 
// and the the MenuGroup which holds them.
public CustomContextMenuProvider()
{   
    // Set up the MenuAction which sets the control's 
    // background to Blue.
    setBackgroundToBlueMenuAction = new MenuAction("Blue");
    setBackgroundToBlueMenuAction.Checkable = true;
    setBackgroundToBlueMenuAction.Execute += 
        new EventHandler<MenuActionEventArgs>(SetBackgroundToBlue_Execute);

    // Set up the MenuAction which sets the control's 
    // background to its default value.
    clearBackgroundMenuAction = new MenuAction("Cleared");
    clearBackgroundMenuAction.Checkable = true;
    clearBackgroundMenuAction.Execute += 
        new EventHandler<MenuActionEventArgs>(ClearBackground_Execute);

    // Set up the MenuGroup which holds the MenuAction items.
    MenuGroup backgroundFlyoutGroup = 
        new MenuGroup("SetBackgroundsGroup", "Set Background");

    // If HasDropDown is false, the group appears inline, 
    // instead of as a flyout. Set to true.
    backgroundFlyoutGroup.HasDropDown = true;
    backgroundFlyoutGroup.Items.Add(setBackgroundToBlueMenuAction);
    backgroundFlyoutGroup.Items.Add(clearBackgroundMenuAction);
    this.Items.Add(backgroundFlyoutGroup);

    // The UpdateItemStatus event is raised immediately before 
    // this provider shows its tabs, which provides the opportunity 
    // to set states.
    UpdateItemStatus += 
        new EventHandler<MenuActionEventArgs>(
            CustomContextMenuProvider_UpdateItemStatus);
}

Hierarquia de herança

System.Object
  Microsoft.Windows.Design.Interaction.MenuBase
    Microsoft.Windows.Design.Interaction.MenuAction

Acesso thread-safe

Quaisquer membros static (Shared no Visual Basic) públicos deste tipo são thread-safe. Não há garantia de que qualquer membro de instância seja thread-safe.

Consulte também

Referência

Membros MenuAction

Namespace Microsoft.Windows.Design.Interaction

PrimarySelectionContextMenuProvider

MenuGroup

Outros recursos

Demonstra Passo a passo: Criando um MenuAction