代码之家  ›  专栏  ›  技术社区  ›  John Rennemeyer

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

  •  0
  • John Rennemeyer  · 技术社区  · 15 年前

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

    谢谢,

    约翰

    1 回复  |  直到 15 年前
        1
  •  0
  •   Jim McCurdy    15 年前

    厕所,

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

    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,面对面软件和银阳钱

    推荐文章