Compartir a través de


MenuAction (Clase)

Actualización: noviembre 2007

Elemento de menú contextual, que representa una acción que se llevará a cabo en el diseñador.

Espacio de nombres:  Microsoft.Windows.Design.Interaction
Ensamblado:  Microsoft.Windows.Design.Extensibility (en Microsoft.Windows.Design.Extensibility.dll)

Sintaxis

Public Class MenuAction _
    Inherits MenuBase

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

Comentarios

Utilice la clase MenuAction para definir un elemento de menú contextual en WPF Designer. 

Para mostrar los elementos del menú contextual, herede de la clase ContextMenuProvider y cree elementos MenuAction y un objeto MenuGroup asociado. Estos objetos de menú suelen crearse en el constructor de una clase derivada de PrimarySelectionContextMenuProvider, que muestra el menú contextual de la selección primaria.

Implemente la lógica para MenuAction en el controlador de eventos Execute.

La clase MenuAction es compatible con el sistema de comandos de WPF. Utilice la propiedad Command para invocar el objeto MenuAction mediante programación en lugar de hacerlo a través de la interfaz de usuario.

Ejemplos

En el siguiente ejemplo de código se muestra cómo configurar dos elementos MenuAction , que establecen la propiedad Background de un control en tiempo de diseño. Para obtener más información, consulte Tutorial: Crear 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);
}

Jerarquía de herencia

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

Seguridad para subprocesos

Todos los miembros static (Shared en Visual Basic) públicos de este tipo son seguros para la ejecución de subprocesos. No se garantiza que los miembros de instancias sean seguros para la ejecución de subprocesos.

Vea también

Referencia

MenuAction (Miembros)

Microsoft.Windows.Design.Interaction (Espacio de nombres)

PrimarySelectionContextMenuProvider

MenuGroup

Otros recursos

Tutorial: Crear MenuAction