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