views:

22

answers:

0

I need to be able to change the size of my Silverlight object at run time because I have content that changes in size dramatically between pages, and I'd rather not show a Silverlight scroll bar inside the browser scroll bar.

I was able to do the following to get it to work:

In the aspx page hosting the silverlight control: - Set your Div to the starting size you need it to be - Set the Silverlight Obejct to width=”100%” height=”100%”

In your Main page add this:

public static void ChangeSize(string height)
    {
        var myDiv = HtmlPage.Plugin.Parent;
        while (myDiv.TagName != "div")
            myDiv = myDiv.Parent;

        myDiv.SetStyleAttribute("height", height);           
    }

Anywhere you want to now change the size of the page do this:

string newHeight = (App.Current.Host.Content.ActualHeight + 75).ToString();
MainPage.ChangeSize(newHeight + "px");
//App.Current.Host.Content.ActualHeight will get the current actual height of the object

Is there a way that I can set this to re-size automatically so that I do not have to specify the amount to change?

Currently using SL 2, interested in if there is another way in a different version though.