开发者

Auto resize Silverlight 3 applications

开发者 https://www.devze.com 2022-12-31 01:07 出处:网络
I\'ve been trying to get a Silverlight 3 application to automatically resize when rows are added to datagrids.

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 exception. 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消