如何从 Outlook 功能区上下文菜单中获取当前邮件项目
我正在创建 Outlook 2010 加载项,并已向我的功能区添加了 idMso="contextMenuMailItem" 的上下文菜单。单击时,我想删除一个类别,但在单击事件处理程序中,当我将 ctl.Context 转换为 MailItem 时,它始终为空。
public bool btnRemoveCategory_IsVisible(Office.IRibbonControl ctl)
{
MailItem item = ctl.Context as MailItem; //Always null
if (item != null)
return (item != null && HasMyCategory(item));
else
return false;
}
有谁知道这是怎么回事?谢谢!
I am creating an Outlook 2010 add-in and have added a context menu to my ribbon for idMso="contextMenuMailItem". On click, I would like to remove a category but in the click event handler, when I cast ctl.Context to MailItem, it's always null.
public bool btnRemoveCategory_IsVisible(Office.IRibbonControl ctl)
{
MailItem item = ctl.Context as MailItem; //Always null
if (item != null)
return (item != null && HasMyCategory(item));
else
return false;
}
Does anyone know what's going on here? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
以下链接可能会为您提供一些见解:
http://msdn.microsoft.com /en-us/library/ff863278.aspx
控件的“上下文”为您提供正在自定义的相应 Outlook 对象(例如 Inspector 对象)。从那里您需要引用上下文对象的 CurrentItem 属性来获取 MailItem。
例如,
希望这有帮助。
The following link might provide you with some insight:
http://msdn.microsoft.com/en-us/library/ff863278.aspx
The "context" of the control gives you the corresponding Outlook object that you are customizing (for example an Inspector object). From there you'll need to reference the context object's CurrentItem property to get the MailItem.
For example,
Hopefully, this helps.
您可以在从所选邮件项目的上下文菜单中触发单击事件后检索邮件项目 -
有关更多详细信息,请访问此处。
You can retrieve Mail Item after click event fired from context menu from selected mail item -
For more details visit here.
当我无法弄清楚动态 ComObject 是什么时,我会使用它。
添加对 Microsoft.VisualBasic 的引用
只是需要它来完成与您几乎相同的事情,我的 IRibbonControl.Context 实际上也是一个选择,尽管它只选择了一个项目。
I use this when I can't work out what a dynamic ComObject is.
Add a reference to Microsoft.VisualBasic
Just needed it for almost the same thing as you, my IRibbonControl.Context was actually a Selection too despite it only being one item selected.
如果您想在 Ribbon.cs 中引用 TheAddin,也许您也可以考虑使用“Globals”。
例如,假设您在解决方案资源管理器中有以下文件:
在“ThisAddin.cs”中声明一个公共 MailItem 并将邮件项分配给它:
然后在 Ribbon1.cs 中使用“Globals”访问它
在我的例子中,“全局”对我有用。
If you want to reference TheAddin in the Ribbon.cs, maybe you could also think to use "Globals".
For instance let say you have like following files in the solution explorer:
Declare a public MailItem lin the 'ThisAddin.cs' and assign the mail item to it:
Then in the Ribbon1.cs access to it by using "Globals"
In my case, the "Globals" worked for me.