.net - Excel 2003 ActionsPane 中的 AutoSize ElementHost

标签 .net wpf winforms excel vsto

我在 Excel 2003 ActionsPane 中托管 WPF 图表。图表设置为水平和垂直拉伸(stretch),但是,虽然 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);

    }

最佳答案

创建一个名为 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 控件(垂直和水平拉伸(stretch))随 Office 应用程序窗口调整大小的额外好处

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

关于.net - Excel 2003 ActionsPane 中的 AutoSize ElementHost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/895507/

相关文章:

.net - Silverlight+WCF 异常 : Expecting application/soap+xml, 收到文本/xml

c# - 控制线程数以平衡 .NET 中的 CPU 和 IO 等待

c# - WPF Richtextbox 以纯文本格式打开 RTF 文件

c# - 在程序中嵌入图像?

c# - 如何取消 Hook C# 中的事件处理程序

.net - 使用 DataTemplate 进行动态 View 绑定(bind)

c# - 我应该将 IDisposable 用于纯托管资源吗?

c# - ViewModel 中的 ObservableCollection,模型中的列表

c# - 从字节数组加载 WPF 图像控件

c# - WinForms DataGridView 即时保存到 Entity Framework 表格