【发布时间】:2013-01-28 22:15:34
【问题描述】:
我正在用 C# 为 Visual Studio 开发一个插件。该插件有一个设置页面和工具栏中的几个按钮来调用命令。
问题是在某些情况下,我想隐藏一个特定的按钮。我能做的最好的事情就是禁用该按钮。
是否可以动态更改其可见性?
编辑:我用手机写了这个问题,所以可能没有足够的细节......
我在 .vsct 文件中创建了工具栏(我在同一个文件中创建了菜单)
<Button guid="guidProductCmdSet" id="startCommand" priority="0x0100" type="Button">
<Parent guid="guidProductCmdSet" id="ToolbarGroup1" />
<Icon guid="Icons" id="startIcon" />
<Strings>
<CommandName>startCommand</CommandName>
<ButtonText>Start</ButtonText>
</Strings>
</Button>
当扩展初始化时,我创建命令:
var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
if (null != mcs)
{
_startCommandId = new CommandID(GuidList.guidProducyVSICmdSet, (int)pkgCmdIDList.startCommand);
var startItem = new MenuCommand(StartProcess, _startCommandId);
mcs.AddCommand(startItem);
}
之后,我可以像这样禁用工具栏中的一些按钮:
var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
var mc = mcs.FindCommand(commandId);
if (mc != null)
{
mc.Enabled = false;
}
我试过 mc.Visible = false,但它什么也没做。
【问题讨论】:
-
您尝试过 Visible 属性吗?例如。 button.Visible = false ?
-
是的,我做到了。奇怪的是它不起作用。很抱歉我的初稿缺乏细节,我在手机上。
标签: c# visual-studio plugins visual-studio-extensions