我正在构建我的第一个Visual Studio扩展,现在我即将结束,我只是想让它看起来好一点。我在顶部菜单中有自己的标题,其中包含项目。我想在菜单中添加一个分隔符以使其更整洁,但无法弄清楚如何操作。
我所说的分隔符是跨菜单/上下文菜单分隔项目的行。
我认为它必须被添加到vsct文件中的xml中,但是它与C#中的加载项相关。
我根本无法找到这个,所以我希望有人可以帮助我。
编辑:我似乎已经弄明白了我的问题。在环顾四周之后,我想到了尝试将几个菜单项放入XML vsct文件中的另一个组......和VOILA!我现在有一个很酷的分隔符。所以答案是它会自动添加到不同的组中,并且不能通过代码完成(或者我认为)。记住Extensions不使用C#或VB来添加菜单项,只有加载项才能。扩展程序使用XML。
答案 0 :(得分:4)
分隔符是.vsct文件中定义的命令组的直观分隔。
命令组是属于一起的命令的逻辑容器。这种分组也可用于视觉效果。
如果在菜单中放置了多个命令组,则会创建一个分隔符,以便在视觉上强调命令组的分离。
要了解有关.vsct文件的更多信息,请查看:http://dotneteers.net/blogs/divedeeper/archive/2008/03/02/LearnVSXNowPart14.aspx
答案 1 :(得分:0)
从这里开始:http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/f26acf64-0ee6-4947-84e4-a7a0ded9d636
看起来这是代码,但老实说我不知道。
'Me.AddSeparatorLine(generateCodeCommandBarPopup, 3)
CType(cmnd_GenerateListDetailFormCode.AddControl(generateCodeCommandBarPopup.CommandBar, 3),CommandBarButton).BeginGroup = True
这看起来似乎也很有用:http://www.mztools.com/articles/2005/MZ2005003.aspx
答案 2 :(得分:0)
在.vcts中,Commands
部分负责该功能。为了动态地使用菜单,您可以实现IVsShellPropertyEvents
界面,并在OnShellPropertyChange
方法中执行逻辑
public int OnShellPropertyChange(int propid, object propValue)
{
// --- We handle the event if zombie state changesfrom true to false
if ((int)__VSSPROPID.VSSPROPID_Zombie == propid)
{
if ((bool)propValue == false)
{
// --- Show the commandbar
EnvDTE80.DTE2 dte = GetService(typeof(DTE)) as DTE2;
CommandBar cb = ((dte.CommandBars as CommandBars)["YourCommandBar"] as CommandBar);
foreach (CommandBarControl cbc in cb.Controls)
{
if (cbc.Caption == "YourCaption")
{
CommandBarButton btn = (CommandBarButton)cbc;
btn.BeginGroup = true; // HERE WE ADD NEW GROUP - means add separator
}
}
}
// --- Unsubscribe from events
var shellService = GetService(typeof(SVsShell)) as IVsShell;
if (shellService != null)
{
ErrorHandler.ThrowOnFailure(shellService.UnadviseShellPropertyChanges(_EventSinkCookie));
}
_EventSinkCookie = 0;
}
return VSConstants.S_OK;
}
答案 3 :(得分:-3)
不确定如何创建菜单,但如果您使用的是MenuItem
类,则可以将"-"
传递给其构造函数以创建分隔符。
MenuItem separator = new MenuItem("-");