如何動態更改ASP.NET面板中嵌入的Silverlight應用程序的高度?'如何更改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>
我的應用程序是這樣的一些數據被表示爲在Canvas
canvas1
的數字,其高度不能預先知道。
截至目前Silverlight應用程序正在被截斷。如何避免這種情況,並確保根據內容放大高度。
觀察:如果我手動更改Height
在Silverlight對象從100%
創建代碼1500px
,高度似乎增加多一點,但還是如果我增加HEIGH進一步內容,甚至裁剪。