Поделиться через


ContextMenuProvider.Items - свойство

Получает пункты для добавления в контекстное меню.

Пространство имен:  Microsoft.Windows.Design.Interaction
Сборка:  Microsoft.Windows.Design.Interaction (в Microsoft.Windows.Design.Interaction.dll)

Синтаксис

'Декларация
Public ReadOnly Property Items As ObservableCollection(Of MenuBase)
    Get
public ObservableCollection<MenuBase> Items { get; }
public:
property ObservableCollection<MenuBase^>^ Items {
    ObservableCollection<MenuBase^>^ get ();
}
member Items : ObservableCollection<MenuBase>
function get Items () : ObservableCollection<MenuBase>

Значение свойства

Тип: System.Collections.ObjectModel.ObservableCollection<MenuBase>
Коллекция ObservableCollection<T> элементов MenuBase.

Примеры

В следующем примере кода показано, как заполнить коллекцию Items для отображения пунктов меню. Дополнительные сведения см. в разделе Пошаговое руководство. Создание поставщика меню.

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

Безопасность платформы .NET Framework

См. также

Ссылки

ContextMenuProvider Класс

Microsoft.Windows.Design.Interaction - пространство имен

PrimarySelectionContextMenuProvider

MenuGroup

MenuAction

FeatureProvider

Другие ресурсы

Поставщики функций и соединительные элементы

Общее представление о расширяемости конструктора WPF