【发布时间】: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对象创建代码中的Height从100%更改为1500px,高度似乎增加了一点,但即使我进一步增加高度,内容仍然被剪裁。
【问题讨论】:
标签: c# asp.net .net silverlight silverlight-4.0