Tutorial :In Silverlight 3 how can I get the call to HtmlPage.Plugin.SetStyleAttribute() call to call other code after the resize?


I'm trying to take a snapshot of my Silverlight control using WriteableBitmap and it works fine, however, it only takes a snapshot of what is showing. I'm trying to resize the Silverlight control so it will show everything and then take a screenshot, however, the code doesn't resize the control until after the code after the call all runs which is the snapshot code...

I can get this work using a timer to fire the snapshot after the other code has caused the resize but I'm wondering if there is a better way. The HtmlPage.Plugin.SetStyleAttribute call has to be called from the UI thread so I'm assuming that's where the problem is. The fact that it is being dispatched onto the UI thread while the rest of the code is not and so the other code is being run first.

Is there anyway to create a new event or attach to the call to determine when it has been run to then fire off my snapshot code?

I have the following code:

private void btnTakeSnapshot_Click(object sender, System.Windows.RoutedEventArgs e)      {          if (CurrentContractAction != null)          {              string heightBefore = HtmlPage.Plugin.GetStyleAttribute("height");              HtmlPage.Plugin.SetStyleAttribute("height", string.Format("{0}px", "1800")); //this line doesn't change the height until after the "TakeSnapshot" code is run for some reason, I'm thinking it is because it is most likely dispatched to the UI thread :( and the following code is not run on the UI thread                Snapshot snapshot = new Snapshot(string.Format("Action_Schedule_{0}", CurrentContractAction.Title), LayoutRoot, LayoutRoot, busyIndicatorDataGrid);                snapshot.HideElements(btnViewGanttChart, btnSave, btnEditAction, btnFullScreen, btnTakeSnapshot, btnLockAndSubmit);                snapshot.TakeSnapshot();                snapshot.ResetElementsVisibility();                HtmlPage.Plugin.SetStyleAttribute("height", string.Format("{0}px", heightBefore));          }      }  





You might want to handle the plugin resize event, take your snapshot there, and then restore the plugin height.

Application.Current.Host.Content.Resized += delegate(object sender, EventArgs e)  {      // Bail if this resize event was not triggered by the snapshot taker      // Take the snapshot      // Restore the plugin height  };  

Good luck,
Jim McCurdy, Face to Face Software and YinYangMoney

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »