title: Silverlight with Dynamic Height
body: <p>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:</p>
  
  <pre><code>// handler in my main page.
   void MainGrid_LayoutUpdated(object sender, EventArgs e)
   {
       HtmlPage.Window.Invoke("setSilverlightSize", this.MainGrid.DesiredSize.Height);
   }
  
  &lt;body style="height:100%;margin:0;"&gt;
      &lt;form id="mainForm" runat="server" style="height:100%;"&gt;
          &lt;asp:ScriptManager ID="ScriptManager" runat="server"&gt;&lt;/asp:ScriptManager&gt;
          &lt;div id="SilverlightContainer"  style="height:100%;"&gt;
              &lt;asp:Silverlight ID="SLMain" runat="server" Source="~/ClientBin/My.Silverlight.Main.xap" Version="2.0" Width="100%" Height="100%" /&gt;
          &lt;/div&gt;
      &lt;/form&gt;
      &lt;script type="text/javascript"&gt;
          function setSilverlightSize(val) {
              var host = document.getElementById("SilverlightContainer");
              host.style.height = val + "px";
          }
      &lt;/script&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>The desired size of the MainGrid always wants to be the size of the window. Argh said the pirate.</p>
  
  <p>-r</p>