Enable/Disable 基于 MailItem 主题的功能区按钮 (Outlook VSTO)
Enable/Disable ribbon button based on MailItem subject (Outlook VSTO)
我在使用非常简单的 VSTO 插件时遇到了一些问题。
我通过设计器(Ribbon1 和 Ribbon2)添加了两个自定义功能区,以便在两个内置功能区(Microsoft.Outlook.Mail.Read
和 Microsoft.Outlook.Explorer
)上创建自定义按钮。
我想根据所选邮件的主题设置功能区按钮的 "Enabled" 属性。
它在 Explorer window/ribbon 中运行良好,但我无法在 Inspector window 中解决它。
问题是 Outlook 只生成一次检查器功能区,所以当我在检查器中打开另一封邮件时 window,我无法更改按钮的状态。我尝试了 Invalidate() 方法并使用 Ribbon XML 和 getEnabled,但我没有成功。有什么问题?
namespace ApproveReport
{
public partial class ThisAddIn
{
// Explorer object
Outlook.Explorer ThisExplorer;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
// SelectionChange Event
ThisExplorer = Globals.ThisAddIn.Application.ActiveExplorer();
ThisExplorer.SelectionChange += new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(ThisExplorer_SelectionChange);
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
// Empty
}
public void ThisExplorer_SelectionChange()
{
if(ThisExplorer.Selection.Count == 1)
{
Outlook.MailItem OriginalMessage = ThisExplorer.Selection[1];
if (OriginalMessage.Subject.Contains("Report"))
{
Globals.Ribbons.Ribbon1.buttonApproveReport.Enabled = true;
Globals.Ribbons.Ribbon2.buttonApproveReport.Enabled = true;
}
else
{
Globals.Ribbons.Ribbon1.buttonApproveReport.Enabled = false;
Globals.Ribbons.Ribbon2.buttonApproveReport.Enabled = false;
}
}
}
}
}
使功能区无效的代码是什么?您处理 getEnabled 回调的代码是什么?
当资源管理器的选择发生变化时,您必须显式调用 Invalidate()。每次为检查器中显示的项目触发 Inspectors.NewInspector
事件时,您都必须执行相同的操作。
我在使用非常简单的 VSTO 插件时遇到了一些问题。
我通过设计器(Ribbon1 和 Ribbon2)添加了两个自定义功能区,以便在两个内置功能区(Microsoft.Outlook.Mail.Read
和 Microsoft.Outlook.Explorer
)上创建自定义按钮。
我想根据所选邮件的主题设置功能区按钮的 "Enabled" 属性。
它在 Explorer window/ribbon 中运行良好,但我无法在 Inspector window 中解决它。
问题是 Outlook 只生成一次检查器功能区,所以当我在检查器中打开另一封邮件时 window,我无法更改按钮的状态。我尝试了 Invalidate() 方法并使用 Ribbon XML 和 getEnabled,但我没有成功。有什么问题?
namespace ApproveReport
{
public partial class ThisAddIn
{
// Explorer object
Outlook.Explorer ThisExplorer;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
// SelectionChange Event
ThisExplorer = Globals.ThisAddIn.Application.ActiveExplorer();
ThisExplorer.SelectionChange += new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(ThisExplorer_SelectionChange);
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
// Empty
}
public void ThisExplorer_SelectionChange()
{
if(ThisExplorer.Selection.Count == 1)
{
Outlook.MailItem OriginalMessage = ThisExplorer.Selection[1];
if (OriginalMessage.Subject.Contains("Report"))
{
Globals.Ribbons.Ribbon1.buttonApproveReport.Enabled = true;
Globals.Ribbons.Ribbon2.buttonApproveReport.Enabled = true;
}
else
{
Globals.Ribbons.Ribbon1.buttonApproveReport.Enabled = false;
Globals.Ribbons.Ribbon2.buttonApproveReport.Enabled = false;
}
}
}
}
}
使功能区无效的代码是什么?您处理 getEnabled 回调的代码是什么?
当资源管理器的选择发生变化时,您必须显式调用 Invalidate()。每次为检查器中显示的项目触发 Inspectors.NewInspector
事件时,您都必须执行相同的操作。