0

我正在尝试使用 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));
        }
    }

谢谢,

约翰

4

1 回答 1

0

约翰,

您可能想要处理插件调整大小事件,在那里拍摄快照,然后恢复插件高度。

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
};

祝你好运,
Jim McCurdy,Face to Face Software 和 YinYangMoney

于 2010-05-19T16:25:38.373 回答