views:

117

answers:

1

I've been trying to get a silverlight 3 application to automatically resize when rows are added to datagrids. I've tried this example but I just get a System.ExecutionEngineException with a null inner exeception. I think this is aimed at silverlight 2 only. Can anyone tell me how to do this in silverlight 3?

Any help on this would be much appreciated.

A: 

I 've got this working with the following:

Add the following javascript to the page with your silverlight object:

 function ResizeObject(height) {
        var host = document.getElementById("silverlightControlHost");
        host.style.height = height + "px";
    } 

Add the following to your silverlight codebehind:

public MainPage()
    {
        InitializeComponent();
        this.Loaded += new RoutedEventHandler(Page_Loaded);
        this.yourRootElement.LayoutUpdated += new EventHandler(LayoutRoot_LayoutUpdated);
    }

    private void LayoutRoot_LayoutUpdated(object sender, EventArgs e)
    {
        HtmlPage.Window.Invoke("ResizeObject", new object[] { this.yourRootElement.RenderSize.Height });
    }

Note that "ResizeObject" refers to the javascript function on your webpage.

bplus