我正在尝试使用WriteableBitmap为我的Silverlight控件拍摄快照,它工作正常,但是,它只拍摄所显示内容的快照。我正在尝试调整Silverlight控件的大小,以便它将显示所有内容,然后拍摄屏幕快照,但是,直到调用后的代码全部运行(即快照代码)之后,代码才调整控件的大小。。。
我可以在其他代码引起大小调整后使用计时器触发快照来完成这项工作,但我想知道是否有更好的方法。HtmlPage.Plugin.SetStyleAttribute调用必须从UI线程调用,所以我假设问题就在这里。它被调度到UI线程上,而其余的代码没有调度到UI线程上,所以其他的代码是先运行的。
我有以下代码:
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));
}
}
谢谢,
约翰