C# Silverlight GetElementById IE6

C# Silverlight GetElementById IE6,c#,asp.net,css,silverlight,internet-explorer-6,C#,Asp.net,Css,Silverlight,Internet Explorer 6,我有一个奇怪的错误,希望你们能帮我解决 我的silverlight应用程序中有以下代码: private void MainGrid_SizeChanged(object sender, SizeChangedEventArgs e) { double actualHeight = this.MainGrid.ActualHeight; HtmlPage.Document.GetElementById("silverlightControlHost").SetStyleAttribute("he

我有一个奇怪的错误,希望你们能帮我解决

我的silverlight应用程序中有以下代码:

private void MainGrid_SizeChanged(object sender, SizeChangedEventArgs e)
{
double actualHeight = this.MainGrid.ActualHeight;
HtmlPage.Document.GetElementById("silverlightControlHost").SetStyleAttribute("height", string.Format("{0}px", actualHeight));
} 
这基本上调整了容器div的大小,使其适合浏览器。这在IE7+、Firefox和Chrome中运行良好。问题是,在IE6中,这不起作用。我不知道为什么

页面标记:

    <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&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>

#silverlightControlHost
{
高度:10px;//在Chrome/IE7+/Firefox中调整大小
文本对齐:居中;
}
有人知道我怎样才能让它按预期工作吗

谢谢,
Simon

您也必须调整对象标记的大小,我只是遇到了同样的问题,我已经签署了onsizechanged事件并更改了容器div的高度和宽度,但是在IE6中,这不起作用,因此一位同事告诉我,在IE6中,您也需要调整对象的大小,所以在标记上放置一个ID并在上面使用它

HtmlPage.Document.GetElementById("objectID").SetStyleAttribute("height", string.Format("{0}px", actualHeight));
在IE6中,DiV“silverlightControlHost”将保持在10px。在所有其他浏览器中,这是根据需要调整silverlight内容的大小,以使其正确地适合页面。