【问题标题】:How to change height of Silverlight app in ASP.NET panel?如何在 ASP.NET 面板中更改 Silverlight 应用程序的高度?
【发布时间】:2012-02-04 06:59:18
【问题描述】:

如何动态更改嵌入在 ASP.NET 面板中的 Silverlight 应用程序的高度?'

ASP.NET 面板标记

<asp:Panel ID="pnlResult" runat="server" Visible="false">
<br />
<div class="cpHeader">
<asp:Label ID="Label1" runat="server" Text="Search Results"></asp:Label>
</div>
<asp:Panel ID="Panel3" runat="server" class='cpResultBody'>
</asp:Panel>
</asp:Panel>

我将 Silverlight 动态添加到上面的 ASP.NET 面板中,Panel3 如下图所示: (这样做是为了动态传递 initparams)

HtmlGenericControl myHtmlObject = new HtmlGenericControl("object");
myHtmlObject.Attributes["data"] = "data:application/x-silverlight-2";
myHtmlObject.Attributes["type"] =  "application/x-silverlight-2";
HtmlGenericControl mySourceParam = new  HtmlGenericControl("param");
mySourceParam.Attributes["name"] = "source";
mySourceParam.Attributes["value"] = "ClientBin/MySilverlightApp.xap";
myHtmlObject.Controls.Add(mySourceParam);    
HtmlGenericControl myOnErrorParam = new HtmlGenericControl("param");   

HtmlGenericControl myInputParam = new HtmlGenericControl("param");
myInputParam.Attributes["name"] = "initparams";
myInputParam.Attributes["value"] = string.Format("param1={0},param2={1},param2={2}", param1.ToString(), param2.ToString(), param3.ToString());
myHtmlObject.Controls.Add(myInputParam);    

myHtmlObject.Attributes["width"] = "100%";
myHtmlObject.Attributes["height"] = "100%";

Panel3.Controls.Add(myHtmlObject);

最后我的 MainPage.xaml 如下。这里我不设置高度。

<UserControl x:Class="MySilverlightApp.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"
xmlns:my="clr-namespace:MySilverlightApp"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
<Grid x:Name="LayoutRoot" Background="WhiteSmoke" >
<Canvas Name="canvas1" HorizontalAlignment="Left" Margin="-1,-1,0,0"
VerticalAlignment="Top"/>
</Grid>
</UserControl>

我的应用程序是这样的,一些数据在Canvascanvas1中表示为数字,其高度无法事先知道。

到目前为止,silverlight 应用程序正在被剪裁。如何避免这种情况并确保根据内容放大高度。

观察:如果我手动将silverlight对象创建代码中的Height100%更改为1500px,高度似乎增加了一点,但即使我进一步增加高度,内容仍然被剪裁。

【问题讨论】:

    标签: c# asp.net .net silverlight silverlight-4.0


    【解决方案1】:

    您可以这样做:当 Silverlight 控件加载到浏览器中时(Loaded 事件),向浏览器发送命令以增大控件所在的 div 以匹配控件的 ActualHeight。 (vb.net)

        'tell the web page to give Silverlight more room.
        Dim so As ScriptObject = TryCast(HtmlPage.Window.Eval("jsnamespace"), ScriptObject)
        so.Invoke("GrowDiv", LayoutRoot.ActualHeight)
    

    这是脚本:

    var jsnamespace = {
    

    GrowDiv:函数(divheight){ //警报(高度); jQuery("body").css("height", divheight); jQuery("#silverlightControlHost").css("height", divheight); jQuery("#Panel3").css("height", divheight); } }

    【讨论】:

      【解决方案2】:

      我不是 Silverlight 方面的专家,但我对这个问题的快速反应是,固定 Grid(layoutroot) 的高度并允许滚动(水平和垂直,无论数据被剪裁的方式),然后提供固定高度HTML 中的 silverlight 对象。

      【讨论】:

        猜你喜欢
        • 2011-02-01
        • 2012-09-09
        • 2014-01-23
        • 1970-01-01
        • 1970-01-01
        • 2023-03-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多