当解决方案具有特定名称时,在上下文菜单中禁用按钮 [英] Disabling button in a context menu when solution has specific name
问题描述
我使用vspackage创建了一个扩展,增加了一个上下文解决方案的菜单(右键单击)。我想禁用命令"创建MVP"。
当解决方案没有特定名称时。
我尝试使用menuItem.Enabled = true,但不起作用。
在这种情况下,我没有具体说明这个名字,但是按照这个步骤我应该启用按钮(设置为禁用)。但它不起作用。
有人能帮帮我吗?
<Button guid="guidWKCommandPackageCmdSet" id="WKCommandId" priority="0x0100" type="Button">
<Parent guid="guidWKCommandPackageCmdSet" id="TopLevelMenuGroup"/>
<Icon guid="guidImages" id="bmpPic1"/>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<CommandName>WKCommandId</CommandName>
<ButtonText>Create MVP</ButtonText>
</Strings>
</Button>
</Buttons>
OleMenuCommandService commandService = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
if (commandService != null)
{
var menuCommandID = new CommandID(CommandSet, CommandId);
var menuItem = new MenuCommand(this.MenuItemCallback, menuCommandID);
commandService.AddCommand(menuItem);
menuItem.Enabled=true;
}
推荐答案
您需要创建一个OleMenuCommand而不是MenuCommand并实现一个BeforeQueryStatus处理程序。
You need to create an OleMenuCommand instead of a MenuCommand and implement a BeforeQueryStatus handler.
您可以在"BeforeQueryStatus"上查询在
GitHub VS Extensibility Samples repo 中,有关如何执行此操作的示例。
You can query on "BeforeQueryStatus" in the
GitHub VS Extensibility Samples repo, for examples of how to do this.
此致
这篇关于当解决方案具有特定名称时,在上下文菜单中禁用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!