MenuAction-Klasse
Aktualisiert: November 2007
Ein Kontextmenüelement, das eine im Designer auszuführende Aktion darstellt.
Namespace: Microsoft.Windows.Design.Interaction
Assembly: Microsoft.Windows.Design.Extensibility (in Microsoft.Windows.Design.Extensibility.dll)
Syntax
'Declaration
Public Class MenuAction _
Inherits MenuBase
'Usage
Dim instance As MenuAction
public class MenuAction : MenuBase
public ref class MenuAction : public MenuBase
public class MenuAction extends MenuBase
Hinweise
Mit der MenuAction-Klasse können Sie ein Kontextmenüelement im WPF-Designer definieren.
Erben Sie zum Anzeigen von Kontextmenüelementen von der ContextMenuProvider-Klasse, und erstellen Sie MenuAction-Elemente mit einer zugehörigen MenuGroup. Diese Menüobjekte werden normalerweise im Konstruktor einer von PrimarySelectionContextMenuProvider abgeleiteten Klasse erstellt, die das Kontextmenü der primären Auswahl anzeigt.
Implementieren Sie die Logik für die MenuAction im Execute-Ereignishandler.
Die MenuAction-Klasse ist mit dem WPF-Befehlssystem kompatibel. Rufen Sie die MenuAction nicht über die Benutzeroberfläche, sondern mithilfe der Command-Eigenschaft programmgesteuert auf.
Beispiele
Im folgenden Codebeispiel wird dargestellt, wie zwei MenuAction-Elemente eingerichtet werden, die die Background-Eigenschaft eines Steuerelements zur Entwurfszeit festlegen. Weitere Informationen finden Sie unter Exemplarische Vorgehensweise: Erstellen einer 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);
}
Vererbungshierarchie
System.Object
Microsoft.Windows.Design.Interaction.MenuBase
Microsoft.Windows.Design.Interaction.MenuAction
Threadsicherheit
Alle öffentlichen static (Shared in Visual Basic)-Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.
Siehe auch
Referenz
Microsoft.Windows.Design.Interaction-Namespace
PrimarySelectionContextMenuProvider