【问题标题】:Visual Studio Addin - Child menu items not appearingVisual Studio 插件 - 未出现子菜单项
【发布时间】:2011-05-21 23:14:57
【问题描述】:

已成功创建顶部菜单项,尝试创建第一个子项但未出现且未引发异常...

void IDTExtensibility2.OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
    _ApplicationObject = (DTE2)application;
    _AddInInstance = (AddIn)addInInst;

    if (connectMode == ext_ConnectMode.ext_cm_Startup)
    {
        object[] contextGUIDS = new object[] { };
        Commands2 commands = (Commands2)_ApplicationObject.Commands;
        CommandBars commandBars = (CommandBars)_ApplicationObject.CommandBars;
        CommandBar cbMainMenu = commandBars["MenuBar"];

        try
        {
            // ROOT MENU
            CommandBarPopup cbpProjectManagement = (CommandBarPopup)cbMainMenu.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, cbMainMenu.Controls.Count, true);
            cbpProjectManagement.Caption = "ROOTMENU";

            // SUB ITEM
            Command cmdCompiledAssemblies = _ApplicationObject.DTE.Commands.AddNamedCommand(_AddInInstance, "VSPM_CA", "CA", 
                String.Empty, true, 0, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled);

            CommandBarControl cbcCompiledAssemblies = (CommandBarControl)cmdCompiledAssemblies.AddControl(cbpProjectManagement.CommandBar, 1);
        }
        catch (Exception ex)
        {
            System.Windows.Forms.MessageBox.Show(ex.ToString());
        }
    }
}

【问题讨论】:

    标签: c# visual-studio-2008 components add-in


    【解决方案1】:

    我知道这个话题很老了——但我遇到了同样的问题,终于找到了解决方案:

    在 QueryStatusMethod 中,您必须检查您的命令(您在上面构建的)并返回有效状态,例如:

        public void QueryStatus(string commandName, vsCommandStatusTextWanted neededText, ref vsCommandStatus status, ref object commandText)
        {
            if(neededText == vsCommandStatusTextWanted.vsCommandStatusTextWantedNone)
            {
                if (commandName == "MetatoolVSAddin.Connect.AddInAboutButton")
                {
                    status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported|vsCommandStatus.vsCommandStatusEnabled;
                    return;
                }
            }
        }
    

    【讨论】:

      【解决方案2】:

      关于如何创建各种菜单和工具栏的完整文档在这里..

      http://www.mztools.com/articles/2005/mz2005003.aspx

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-12-28
        • 2014-04-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多