views:

254

answers:

2

Hi there,

I am currently working on a silverlight business application, so I have come across a little problem and I am looking for some asssistence.

In the application I am developing some pages (in the silverlight) can become quite long, but what I am finding is that the ASPX or Browser is determining the page size and the hence the silverlight control tries to fit this... but can't so it clips the the content.

The behaviour I am looking for is as follows:

All grids are set to Auto to allow them to take on the size of their content (images, form expanders, etc) this should allow the grid to grow (Vertical at least) and this should create scrollbars in the browser as the Silverlight expands to fit/accommodate the content.

How do I achieve this behaviour?

Basically all the ASPX page is, is a container for the Silverlight... the entire application will be done through Silverlight.

A: 

The behavior you're facing is due to the limits the HTML sets on the control. It can be solved by placing height of 100% on all containers hierarchy in advance and notify the body element when the size of the control changes:

HTML For example:

<html xmlns="http://www.w3.org/1999/xhtml" style="height:100%;">
<head runat="server">
    <title>SilverlightApplication1</title>
</head>
<body style="height:100%;margin:0;">
    <form id="form1" runat="server" style="height:100%;">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <div  style="height:100%;">
            <asp:Silverlight ID="Xaml1" runat="server" Source="~/ClientBin/SilverlightApplication1.xap" MinimumVersion="2.0.31005.0" Width="100%" Height="100%" />
        </div>
    </form>
</body>
</html>

And the notification in the control code behind:

public Page()
{
    InitializeComponent();
    SizeChanged += new SizeChangedEventHandler(Page_SizeChanged);

}

void Page_SizeChanged(object sender, SizeChangedEventArgs e)
{
    HtmlPage.Document.Body.SetStyleAttribute("height", e.NewSize.Height + "px");
}
Elisha
Thanks will give it a go.
Oliver
This is semi working... problem is that I am using teh RIA Framework and the User control (which is the master page) gets the size of the windows again... I have to do this on the inner-pages and then add onto the size to take into account for the banner and various other elements on the master form.Advice?
Oliver
A: 

This is what I did eventually, It's far from perfect but maybe someone can take it and improve it:

 private void Page_SizeChanged(object sender, SizeChangedEventArgs e)
    {
        BrowserInformation oInfo = System.Windows.Browser.HtmlPage.BrowserInformation;

        double nHeight=0;
        if (oInfo.Name.ToLower().Contains("explorer"))
        {
            nHeight = (double)HtmlPage.Document.DocumentElement.GetProperty("clientHeight");
        }
        else if (oInfo.Name.ToLower().Contains("netscape"))
        {
            nHeight = (double)HtmlPage.Window.GetProperty("innerHeight");
        }


        if ((e.NewSize.Height + 160) > nHeight)
        {
            HtmlPage.Document.Body.SetStyleAttribute("height", (e.NewSize.Height + 160) + "px");
        }
        else
        {
            HtmlPage.Document.Body.RemoveAttribute("style");
        }
    }
Oliver