Excel 2003 ActionsPane中的AutoSize ElementHost

我在Excel 2003 ActionsPane中托pipe一个WPF图表。 图表设置为水平和垂直拉伸,但是,尽pipeElementHost和图表横向填充了ActionsPane,但是我还没有find一种方法来使ElementHost垂直填充。 似乎对ElementHost的布局有任何影响的唯一属性是“高度”和“大小”属性。 Anchor,Dock,AutoSize似乎不会影响ActionsPane对象或ElementHost对象上的布局。

我错过了什么吗?

问候,

丹尼

// A snippet from ThisWorkbook.cs public partial class ThisWorkbook { private void ThisWorkbook_Startup(object sender, System.EventArgs e) { var ap = Globals.ThisWorkbook.ActionsPane; ap.Clear(); ap.Visible = true; var plotControl1 = new Swordfish.WPF.Charts.TestPage(); var elementHost1 = new System.Windows.Forms.Integration.ElementHost(); elementHost1.AutoSize = true; // Doesn't seem to have an effect. elementHost1.Child = plotControl1; ap.Controls.Add(elementHost1); } 

创build一个名为我的ActionPane的自定义WPF表单,并将其托pipe在ElementHost中。 以下是我如何做ElementHost本身:

 private void ThisDocument_Startup(object sender, System.EventArgs e) { ActionPane actionPaneControl = new ActionPane(); this.ActionsPane.Resize += new EventHandler(ActionsPane_Resize); this.ActionsPane.Controls.Add(new ElementHost { Child = actionPaneControl, AutoSize = true }); } 

基本上我订阅了ActionsPane Resize事件,并根据这个事件调整了ElementHost对象的大小。 这使得WPF控制(包括vert和horiz伸展)的附加好处与Office应用程序窗口一起resize

 void ActionsPane_Resize(object sender, EventArgs e) { ((this.ActionsPane.Controls[0] as ElementHost).Child as ActionPane).Height = this.ActionsPane.Height; }