I've been trying to get a Silverlight 3 application to automatically resize when rows are added to datagrids.
I've tried
this example
but I just get a System.ExecutionEngineException
with a null inner exception. I think this is aimed开发者_运维问答 at Silverlight 2 only.
Can anyone tell me how to do this in Silverlight 3?
Any help on this would be much appreciated.
I 've got this working with the following:
Add the following javascript to the page with your silverlight object:
function ResizeObject(height) {
var host = document.getElementById("silverlightControlHost");
host.style.height = height + "px";
}
Add the following to your silverlight codebehind:
public MainPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Page_Loaded);
this.yourRootElement.LayoutUpdated += new EventHandler(LayoutRoot_LayoutUpdated);
}
private void LayoutRoot_LayoutUpdated(object sender, EventArgs e)
{
HtmlPage.Window.Invoke("ResizeObject", new object[] { this.yourRootElement.RenderSize.Height });
}
Note that "ResizeObject" refers to the javascript function on your webpage.
精彩评论