调整Silverlight容器div的大小会使Silverlight在Firefox中重新加载



想知道是否有人找到了一个简单的解决方案。看起来好像你不能通过在Silverlight对象上使用100%的宽度/高度,然后在FIrefox中动画容器div的高度和宽度来控制Silverlight的大小。我想知道是否有人找到了一个解决办法。非常令人沮丧的是,以下内容在除Firefox之外的所有浏览器中都可以正常工作。

你可以看到,当你在Firefox中点击test时,Silverlight控件消失了,Silverlight对象必须重新加载自己。在其他浏览器中,它不需要重新加载,只是动画效果很好。为什么是火狐,为什么?现在我不得不恨你了。

UserControl x:Class="testFirefox.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
    <Border BorderThickness="4" BorderBrush="Black">
        <Grid x:Name="LayoutRoot" Background="White" HorizontalAlignment="Center" VerticalAlignment="Center">
            <TextBlock Text="Center" FontSize="30"></TextBlock>
        </Grid>
    </Border>
</UserControl>
<%@ Page Language="C#" AutoEventWireup="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>testFirefox</title>
    <script type="text/javascript" src="Silverlight.js"></script>
    <script src="jquery-1.6.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#testSilverlight").click(function () {
                $("#silverlightControlHost").animate({ width: 700 }, 2000, 'swing');
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server" style="height:100%">
    <div id="silverlightControlHost" style="height:300px; width: 300px;">
        <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
          <param name="source" value="ClientBin/testFirefox.xap"/>
          <param name="onError" value="onSilverlightError" />
          <param name="background" value="white" />
          <param name="minRuntimeVersion" value="4.0.50826.0" />
          <param name="autoUpgrade" value="true" />
          <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration:none">
              <img src="http://go.microsoft.com/fwlink/?LinkId=161376" 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>
        <div id="testSilverlight" style="height:50px; width:50px; border: 1px solid black;">
         TEST
      </div>
    </form>
</body>
</html>

这是因为jQuery animate改变了容器的溢出,导致silverlight重新加载。当您在firefox上更改容器的显示或位置时,可能会发生类似的情况。我已经解决了这个问题,注释了jQuery 1.6.4的第8266行(这行可能在1.5之后的其他版本上接近)未压缩版本,上面写着
This.style.overflow = "hidden";
希望这对你有帮助。马科斯。

最新更新