2017-08-31 150 views
0

我試圖添加一個新元素到Visual Studio 2017上下文菜單。我設法元素用下面的代碼添加到工具菜單:Visual Studio擴展:向代碼編輯器添加元素ContextMenu

<Button guid="guidRandomCommandPackageCmdSet" id="RandomCommandId" priority="0x0100" type="Button"> 
    <Parent guid="guidSHLMainMenu" id="IDG_VS_TOOLS_EXT_TOOLS" /> 
    <Icon guid="exclamationIcon" id="exclamationIcon1" /> 
    <Strings> 
     <ButtonText>Random Text</ButtonText> 
    </Strings> 
    </Button> 

這是在

<GuidSymbol name="guidRandomCommandPackageCmdSet" value="{47122772-c66f-48f3-b10b-dbbb66da120d}"> 
    . 
    . 
    <IDSymbol name="RandomCommandId" value="0x0100" /> 
</GuidSymbol> 

我試圖按照類似的方式註冊,所以我在Buttons定義了一個新Button

<Button guid="guidRandomCommandPackageCmdSet" id="ToDoList" priority="0x0100" type="Button"> 
    <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_CODEWIN"/> 
    <Icon guid="exclamationIcon" id="exclamationIcon1" /> 
    <Strings> 
     <ButtonText>Add TODO list</ButtonText> 
    </Strings> 
    </Button>with the ID symbol 

在GuidSymbols的ID registerd

<IDSymbol name="ToDoList" value="0x106" /> 

但是,當我運行項目時,按鈕不會顯示在上下文菜單中。我試圖按照VSIX: Adding a Menu Item to the Visual Studio Editor Context Menu的建議,但沒有任何建議似乎對我有用。 我從來沒有嘗試過創建一個VS插件,所以我歡迎任何建議。該方法是否可能在VS 2017中更改?

回答

0

最終,我設法讓它工作。看起來,對於顯示爲單獨菜單或屬於像TOOLS這樣的菜單的菜單項,似乎只有一個Button,其中父設置爲GUIDs and IDs of Visual Studio Menus處定義的適當的常數菜單元素串就足夠了。

對於ContextMenu元件,但是,我需要有一個元件在Groups

<Group guid="guidRandomCommandPackageCmdSet" id="MyMenuGroup" priority="0x0600"> 
    <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_CODEWIN" /> 
    </Group> 

這具有的ContextMenu作爲其Parent。然後,我創建了一個CustomCommand是自動生成Button用它,我修改了這個ButtonGroup元素作爲Parent: ` 添加TODO列表

這是與結果添加按鈕懸停在:

Button on Context Menu

相關問題