views:

175

answers:

1

Hi, I have an odd error that you guys will hopefully be able to help me out with.

I have this code in my silverlight app:

private void MainGrid_SizeChanged(object sender, SizeChangedEventArgs e)
{
double actualHeight = this.MainGrid.ActualHeight;
HtmlPage.Document.GetElementById("silverlightControlHost").SetStyleAttribute("height", string.Format("{0}px", actualHeight));
}

This basically resizes my container div so that it fits in the browser. This is working fine in IE7+, Firefox and Chrome. The problem is that in IE6 this is not working. And im not sure why.

Page markup:

    <style type="text/css">
        #silverlightControlHost
        {
            height: 10px; //This gets resized in Chrome/IE7+/Firefox
            text-align: center;
        }
    </style>

    <script type="text/javascript" src="../Silverlight.js"></script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div id="silverlightControlHost">
        <object data="data:application/x-silverlight-2," type="application/x-silverlight-2"
            width="100%" height="100%">
            <param name="enablehtmlaccess" value="true"/>
            <param name="source" value="../ClientBin/myAppXap.xap" />
            <param name="onError" value="onSilverlightError" />
            <param name="background" value="white" />
            <param name="minRuntimeVersion" value="3.0.40624.0" />
            <param name="autoUpgrade" value="true" />
            <a href="http://go.microsoft.com/fwlink/?LinkID=149156&amp;v=3.0.40624.0" style="text-decoration: none">
                <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight"
                    style="border-style: none" />
            </a>
        </object>
        <iframe id="_sl_historyFrame" style="visibility: hidden; height: 0px; width: 0px;
            border: 0px"></iframe>
    </div>
</asp:Content>

Does anyone have any ideas how i can get this working as desired?

Thanks, Simon

+1  A: 

You have to resize your object tag as well, i just had the same problem, i had signed the onsizechanged event and changed the height and width of the container div, however in IE6 that didn't worked, so a co-worker told me that in IE6 you need to resize the object as well, so place an ID on your tag and use it on this

HtmlPage.Document.GetElementById("objectID").SetStyleAttribute("height", string.Format("{0}px", actualHeight));
Gabriel Guimarães
Exactly right, thanks for that. Works a treat.
Kohan