c# - 仅在代码窗口打开时启用我的 Visual Studio 扩展的菜单项
问题描述
我只想在代码编辑器打开时启用我的扩展菜单项。
我尝试检测何时使用以下代码打开代码窗口而没有成功结果...
private void MenuItem_BeforeQueryStatus(object sender, EventArgs e)
{
OleMenuCommand menuCommand = sender as OleMenuCommand;
if (null != menuCommand)
{
IVsMonitorSelection monitorSelection = this.ServiceProvider.GetService(typeof(IVsMonitorSelection)) as IVsMonitorSelection;
int pfActive;
Guid codeWindowGuid = VSConstants.UICONTEXT_CodeWindow;
uint solutionExistCookie;
monitorSelection.GetCmdUIContextCookie(ref codeWindowGuid, out solutionExistCookie);
monitorSelection.IsCmdUIContextActive(solutionExistCookie, out pfActive);
menuCommand.Enabled = (pfActive == 1);
}
}
虽然IsCmdUIContextActive
正在恢复S_OK
,但即使代码窗口确实打开了,我也总是将 pfActive 接收为 false ..
我究竟做错了什么 ?
解决方案
也许您忘记在方法签名中定义的地方添加out
关键字?IsCmdUIContextActive
推荐阅读
- parallel-processing - 如何避免矩阵乘法 CUDA 内核中的未合并访问?
- sapui5 - 未显示 GenericTile 中内容的所有内容
- dialogflow-es - 我应该在哪里查看错误“MalformedResponse 无法将 Dialogflow 响应解析为 AppResponse,因为语音响应为空
- c# - 如何将子查询转换为联接以获得快速结果?
- python - 填充
- xamarin - 在单选按钮控件中如何实现单选圈前的文字?
- android - 导航组件的 popUpTo 不删除向上按钮
- java - 弃用 FileUtils.writeStringToFile 方法的替代方法是什么?
- python - Python中的int到日期时间
- antd - 自定义 ant.design 组件样式