CommandSet.GetMenuCommands - метод
Отображает команды в контекстном меню.
Пространство имен: Microsoft.VisualStudio.Modeling.Shell
Сборка: Microsoft.VisualStudio.Modeling.Sdk.Shell.12.0 (в Microsoft.VisualStudio.Modeling.Sdk.Shell.12.0.dll)
Синтаксис
'Декларация
Protected Overrides Function GetMenuCommands As IList(Of MenuCommand)
protected override IList<MenuCommand> GetMenuCommands()
Возвращаемое значение
Тип: System.Collections.Generic.IList<MenuCommand>
Список команд меню.
Заметки
Можно переопределить этот метод и добавьте собственные команды. Чтобы добавить собственные команды, укажите их в файле пользовательские .vsct и вызывайте их в пользовательском файле CS.
Примечание
Не добавляйте изменения в файл CommandSet.cs.Этот файл повторной генерации при каждом построении, созданный конструктором.
Примеры
Этот пример добавляет пользовательской команды в контекстное меню. Когда пользователь выполняет построение решения в созданном конструктора и щелкните схему, одна дополнительная команды Проверить, отображается в контекстное меню.
В файле Commands.vsct, следующая линия отображается после выписок include.
#define AssociationSortValidate 0x801
В файле Commands.vsct, следующая линия отображается после GENERATED_BUTTONS.
guidCmdSet:AssociationSortValidate, guidCmdSet:grpidContextMain, 0x0100, OI_NOID, BUTTON, DIS_DEF, "&Validate";
В папку VsctComponents, следующий файл CS доступен. Пространство имен и некоторые методы, имеющие имя проекта MenuSample в них.
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel.Design;
using Microsoft.VisualStudio.Modeling;
using Microsoft.VisualStudio.Modeling.Shell;
namespace MS.MenuSample
{
internal partial class MenuSampleCommandSet
{
// Define the command. This must be unique and match the value in Commands.vsct.
private const int AssociationSortValidate = 0x801;
// Register event handlers for menu commands when the Domain-Specific Language Designer starts.
// Get the commands defined in the generated code.
protected override IList<System.ComponentModel.Design.MenuCommand> GetMenuCommands()
{
global::System.Collections.Generic.IList<global::System.ComponentModel.Design.MenuCommand> commands = base.GetMenuCommands();
commands.Add(new DynamicStatusMenuCommand(
new EventHandler(OnStatusChangeAssociationSort),
new EventHandler(OnMenuChangeAssociationSort),
CustomCommandId(AssociationSortValidate)));
return commands;
}
// Set whether a command should appear in the shortcut menu by default.
internal void OnStatusChangeAssociationSort(object sender, EventArgs e)
{
MenuCommand command = sender as MenuCommand;
command.Visible = command.Enabled = true;
}
// Perform an Association Sort command on the current selection.
internal void OnMenuChangeAssociationSort(object sender, EventArgs e)
{
MenuCommand command = sender as MenuCommand;
}
// Create local command IDs that are unique.
private CommandID CustomCommandId(int command)
{
return new CommandID(new Guid(Constants.MenuSampleCommandSetId), command);
}
}
}
Безопасность платформы .NET Framework
- Полное доверие для непосредственно вызывающего метода. Этот член не может быть использован частично доверенным кодом. Дополнительные сведения см. в разделе Использование библиотек из не вполне надежного кода.