views:

29

answers:

2

Hello,

I want to embed a silverlight app into a web page and have the height/width of the div that contains the silverlight control match the dimensions of the actual size of the silverlight control.

I essentially want the div to stretch to accommodate the size of the silverlight control. I do not know what size the silverlight control will be before it loads as it is pulling in data and adding controls dynamically.

I want to avoid dueling scroll bars and use only the browser scroll bars.

I need this to work in both IE and Firefox.

Is there a way to accomplish this?

+1  A: 

You could set the height to 100% and put a

<div style="clear:both"></div>

at the end of it to make it fill the parent control.

Mark Avenius
A: 

Yes it can be done. There are two methods:

  • set your plugin control to be 100% height and width, then use a div around it to control its size. Then call a javascript function through the javascript bridge, and have that function manipulate the div by using document.getElementById() or jQuery
  • forget about controlling a div and use HtmlPage.Plugin from your managed code, this avoids the javascript bridge and gives you access to the plugin container itself, then you can just set the width/height like this:

    HtmlPage.Plugin.SetStyleAttribute("height", height + "px");

Note that FFox from about v3.6.8 onwards has an issue if you try to manipulate the plugin style attributes repeatedly too rapidly, i don't know if the recently released v3.6.11 suffers from the same problem.

slugster
What event should I call "HtmlPage.Plugin.SetStyleAttribute("height", height + "px");" from?How do I get the actual size of the silverlight control?
jesse
@jesse: you should be able to use it anytime after the silverlight application's `Load` event, personally i use it in response to user input to shrink/expand a SL control i have on the HTML page. `HtmlPage.Plugin` is the HTML object control, so you can use GetStyleAttribute() to read its style (it may not tell you much though), or you can use the ActualHeight/ActualWidth of the silverlight app's main form.
slugster