I created a Visual Studio Add-in that adds additional commands (four of them) to the top of Code Window context menu. I'm using permanent UI approach. Depending on the cursor position within code only one of the commands would be visible and thus selectable. Other three would be hidden.
我创建了一个Visual Studio加载项,它将其他命令(其中四个)添加到代码窗口上下文菜单的顶部。我正在使用永久UI方法。根据代码中的光标位置,只有一个命令是可见的,因此是可选择的。其他三个将被隐藏。
I set supported and enabled status within QueryStatus
method that does the trick for the correct command and unsupported and invisible for the rest.
我在QueryStatus方法中设置了支持和启用状态,该方法为正确的命令提供技巧,对其余命令不支持和不可见。
The problem
The first time add-in is installed all works well. I can only see a single command in the context menu. The rest are always hidden.
The second time I load VS IDE I detect the same commands and controls (so I don't recreate something that's already there), but now all of the commands (or better CommandBarControl/CommandBarButton
controls) are visible. Instead of hiding 3 and showing only one I can see all four of them. The correct one is enabled and the rest of the pack is disabled/grayed out.
问题第一次安装加载项一切正常。我只能在上下文菜单中看到一个命令。其余的总是隐藏的。第二次加载VS IDE我检测到相同的命令和控件(所以我不重新创建已存在的东西),但现在所有命令(或更好的CommandBarControl / CommandBarButton控件)都可见。而不是隐藏3而只显示一个,我可以看到它们全部四个。正确的一个被启用,其余的包被禁用/变灰。
The question
How do I hide existing commands (or CommandBarButton
controls) on the next IDE load? I tried setting button's Visible
property to false
but then even the correct control isn't displayed.
问题如何在下一次IDE加载时隐藏现有命令(或CommandBarButton控件)?我尝试将按钮的Visible属性设置为false,但是甚至没有显示正确的控件。
2 个解决方案
#1
Have you tried having a single command, and changing the text of command depending on the cursor position? I'm not sure if this is possible, just a suggestion.
您是否尝试过单个命令,并根据光标位置更改命令文本?我不确定这是否可行,只是一个建议。
#2
Solution I used at the end was:
我最后使用的解决方案是:
- Delete controls at IDE startup (or Add-in after startup if not enabled at IDE startup by default). Deleting commands also removes any controls
- Recreate commands and controls and their visibility will work as expected.
在IDE启动时删除控件(如果在IDE启动时未启用,则在启动后删除加载项)。删除命令也会删除任何控件
重新创建命令和控件,它们的可见性将按预期工作。
#1
Have you tried having a single command, and changing the text of command depending on the cursor position? I'm not sure if this is possible, just a suggestion.
您是否尝试过单个命令,并根据光标位置更改命令文本?我不确定这是否可行,只是一个建议。
#2
Solution I used at the end was:
我最后使用的解决方案是:
- Delete controls at IDE startup (or Add-in after startup if not enabled at IDE startup by default). Deleting commands also removes any controls
- Recreate commands and controls and their visibility will work as expected.
在IDE启动时删除控件(如果在IDE启动时未启用,则在启动后删除加载项)。删除命令也会删除任何控件
重新创建命令和控件,它们的可见性将按预期工作。