C# – Auto Size Silverlight Application

csilverlight-2.0

I want to have my silverlight application to auto size it self to the contents within the application by changing the height of the Host div. How would you get what the size of the total app should be?

For instance I have a Grid with three rows, The top and bottom row have buttons and the middle row has a DataGrid that can change in height based on the page size the user has selected. I want the app to adjust the Host div's height to the height to display the entire app.

Best Answer

You've got two options here.

  1. You can manipulate the DOM directly through the HtmlPage property (I would suggest giving the hosting div a unique ID to help you locate it)
  2. Write a javascript function that resizes based on some parameters e.g. function resizeSLHost(width, height). You can then call the javascript function from silverlight and pass it the actual height and width.