views:

148

answers:

1

Hi,

I'm hosting a WPF chart in an Excel 2003 ActionsPane. The chart is set to stretch both horizontally and vertically, however, although the ElementHost and the chart fill the ActionsPane horizontally, I have not found a way to enable the ElementHost to fill vertically. The only property that seems to have any affect on the layout of the ElementHost is the Height and Size properties. Anchor, Dock, AutoSize don't seem to effect the layout either on the ActionsPane object or the ElementHost object.

Am I missing something?

regards,

Danny

// 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);

    }
+1  A: 

create a custom WPF form called my ActionPane and hosted it in an ElementHost. Here is how I did the ElementHost itself:

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 });
    }

Basically I subscribe to the ActionsPane Resize event and size the ElementHost object based off of that. This gives the added side benefit of the WPF contorl (with both vert and horiz stretch) resizing along with the Office application Window

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