【问题标题】:Silverlight GetElementById IE6Silverlight GetElementById IE6
【发布时间】:2009-10-01 16:37:48
【问题描述】:

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

我的 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>

有没有人知道我怎样才能让它按需要工作?

谢谢, 西蒙

【问题讨论】:

  • 在 IE6 中,DiV "silverlightControlHost" 将保持在 10px。在所有其他浏览器中,这会根据需要调整 silverlight 内容的大小,以便它正确地适合页面。

标签: c# asp.net css silverlight internet-explorer-6


【解决方案1】:

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

HtmlPage.Document.GetElementById("objectID").SetStyleAttribute("height", string.Format("{0}px", actualHeight));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-20
    • 2010-10-08
    • 2011-08-19
    • 2014-02-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多