我在Excel2003 ActionsPane中托管了一个WPF图表。图表被设置为水平和垂直拉伸,但是,尽管ElementHost和图表水平填充ActionsPane,但我还没有找到一种使ElementHost能够垂直填充的方法。唯一对ElementHost布局有影响的属性是Height和Size属性。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);
}发布于 2010-01-05 04:48:39
创建名为my ActionPane的自定义WPF窗体,并将其承载在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控制(具有顶点和水平拉伸)随Office应用程序窗口一起调整大小的附加好处
void ActionsPane_Resize(object sender, EventArgs e)
{
((this.ActionsPane.Controls[0] as ElementHost).Child as ActionPane).Height = this.ActionsPane.Height;
}https://stackoverflow.com/questions/895507
复制相似问题