[英]hiding a button from a plugin toolbar
I am developping a plugin for Visual Studio in C#. 我正在为C#中的Visual Studio开发一个插件。 The plugin has a settings page and a few buttons in a toolbar to call commands.
该插件有一个设置页面和工具栏中的几个按钮来调用命令。
The problem is that in some circonstances, I want to hide a specific button. 问题是在某些情况下,我想隐藏一个特定的按钮。 The best I was able to do is to disable the button.
我能做的最好的就是禁用按钮。
Is it possible to dynamically change it's visibility? 是否有可能动态改变其可见性?
EDIT: I wrote this question from my mobile, so maybe there is not enough details... 编辑:我从我的手机上写了这个问题,所以可能没有足够的细节......
I create the toolbar in the .vsct file (I created the menu in the same file) 我在.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>
When the extension initializes, I create the commands: 当扩展程序初始化时,我创建命令:
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);
}
After, I am able to disable some buttons from the toolbar like this: 之后,我可以禁用工具栏中的一些按钮,如下所示:
var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
var mc = mcs.FindCommand(commandId);
if (mc != null)
{
mc.Enabled = false;
}
I tried mc.Visible = false, but it does nothing. 我试过mc.Visible = false,但它什么也没做。
Apparently, this works... 显然,这有效......
var commandBars = ((CommandBars)_dte2.CommandBars);
if (commandBars == null)
{
return;
}
var commandBar = commandBars["MyPluginProductName"];
if (commandBar == null)
{
return;
}
var startButton = commandBar.Controls["startCommand"];
if (startButton == null)
{
return;
}
startButton.Visible = false;
Add 加
<CommandFlag>AllowVisibilityChangeOnToolBar</CommandFlag>
to your button. 到你的按钮。
Best Regards, 最好的祝福,
Konstantin S. 康斯坦丁S.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.