我在任务窗格中遇到WPF控件问题。我使用ElementHost
添加了它。因此,如果我显示任务窗格,则NewInspector
和检查员Close
不再提升。
这是我的代码
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
<ribbon>
<tabs>
<tab idMso="TabNewMailMessage">
<group label="MyGroup" id="mygroup">
<button id="addItemBlabla"
size="large"
label="Add Items"
onAction="AddItemsClick"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
//..Ribbon.cs file
public void AddItemsClick(Office.IRibbonControl ribbonControl)
{
Inspector inspector = ribbonControl.Context as Inspector;
if (this.taskPane == null)
{
this.taskPane = Globals.ThisAddIn.CustomTaskPanes.Add(new MyUserControlThatContainsWpfElementHost(), "Label", this.inspector);
}
this.taskPane.Visible = true;
}
//.. ThisAddIn.cs file
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.Inspectors.NewInspector += this.Inspectors_NewInspector;
}
private void Inspectors_NewInspector(Outlook.Inspector Inspector)
{
//Does not work after task pane is shown!!!
}
更新 如果我在设计器中使用Ribbon,则此示例有效,但我需要使用XML版本
答案 0 :(得分:1)
我解决了我的问题。你可以在这里找到答案 https://social.msdn.microsoft.com/Forums/vstudio/en-US/73ea73da-8597-4152-938d-2ff99a82960f/newinspector-and-close-event-does-not-raise-if-wpf-control-used-in-task-pane?forum=vsto
我们需要在代码中添加inspectors字段:
//..ThisAddIn.cs
private Inspectors inspectors;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.inspectors = this.Application.Inspectors;
this.inspectors.NewInspector += this.Inspectors_NewInspector;
}
private void Inspectors_NewInspector(Outlook.Inspector Inspector)
{
//Now this works!!!
}