在 Silverlight 3 中,如何在调整大小后调用 HtmlPage.Plugin.SetStyleAttribute() 来调用其他代码?

发布于 2024-09-02 06:40:48 字数 1452 浏览 0 评论 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));
        }
    }

谢谢,

约翰

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

Thanks,

John

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

他不在意 2024-09-09 06:40:48

约翰,

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

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

John,

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文