I have a silverlight app that I want to allow to size like a regular HTML page. That is, I want the size of the silverlight plugin to expand and contract in height to accommodate the dynamic data and controls that I am populating the silverlight app with. So, say I have a Page with a Grid and a button. The user hots the button and the grid gets a bunch of rows with images making the natural size of the grid higher than the browser windows. I would like to have something in place to resize the silverlight plugin to accomidate the DesiredSize of the Grid. The following, and several other attempts, are not working:
// handler in my main page.
void MainGrid_LayoutUpdated(object sender, EventArgs e)
{
HtmlPage.Window.Invoke("setSilverlightSize", this.MainGrid.DesiredSize.Height);
}
<body style="height:100%;margin:0;">
<form id="mainForm" runat="server" style="height:100%;">
<asp:ScriptManager ID="ScriptManager" runat="server"></asp:ScriptManager>
<div id="SilverlightContainer" style="height:100%;">
<asp:Silverlight ID="SLMain" runat="server" Source="~/ClientBin/My.Silverlight.Main.xap" Version="2.0" Width="100%" Height="100%" />
</div>
</form>
<script type="text/javascript">
function setSilverlightSize(val) {
var host = document.getElementById("SilverlightContainer");
host.style.height = val + "px";
}
</script>
</body>
The desired size of the MainGrid always wants to be the size of the window. Argh said the pirate.
-r