Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Preserve WPF's cached rendering (Read 3448 times)
riemaecker
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 8
Joined: Jul 31st, 2009
Preserve WPF's cached rendering
Nov 2nd, 2010 at 1:29pm
Print Post  
Our application uses the diagram control within a docking control from Actipro. When "docking out" the diagram window, we are faced with the problem that everything needs to be layouted/rendered again because the following happens:

- The diagram docking window is removed from the MainWindow's VisualTree.
- A real window is created.
- The previous content of the diagram docking window is assigned to that new window, therefore inserted into a new Visual Tree

Due to this operation, the Mindfusion diagram needs to be layouted and rendered again Undecided

While this is a technical issue of WPF, I think this is a pretty common scenario (Diagram + Docking) and I want to know if anybody has an idea how to deal with this?

To sum this up, I want to preserve the rendering that has already be done when the diagram control is removed/inserted into a visual tree.

P.S.: Our diagram is interactive and needs input, so caching a bitmap or any similar "static" solution wouldn't be a solution for us.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Preserve WPF's cached rendering
Reply #1 - Nov 2nd, 2010 at 6:41pm
Print Post  
Hi,

How big is that diagram if it's so slow to render? You could try to handle some kind of preview-undock event, call VisualTreeHelper.GetDrawing(diagram) to get a cached drawing, place it in the window as an overlay over the diagram and remove it some time after docking-out completes.

Stoyan
  
Back to top
 
IP Logged
 
riemaecker
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 8
Joined: Jul 31st, 2009
Re: Preserve WPF's cached rendering
Reply #2 - Nov 3rd, 2010 at 10:48am
Print Post  
didn't know anything of VisualTreeHelper.GetDrawing(...)! It is barely mentioned anywhere.
Thank you, you opened a whole new world to me Smiley
  
Back to top
 
IP Logged
 
riemaecker
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 8
Joined: Jul 31st, 2009
Re: Preserve WPF's cached rendering
Reply #3 - Nov 3rd, 2010 at 3:00pm
Print Post  
I gave it a shot, but without any positive results.

Using either of the following lines, everything returns null:

VisualTreeHelper.GetDrawing((Visual)VisualTreeHelper.GetChild(this.Diagram.Diagr
amPlane, 1))

VisualTreeHelper.GetDrawing(this.Diagram.DiagramPlane)

VisualTreeHelper.GetDrawing(this.Diagram)

I even tried it on a button and the MainWindow itself. Did I miss some important fact? Unfortunately, the MSDN documentation is very sparse.

I also made sure that everything is already rendered before calling the method.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Preserve WPF's cached rendering
Reply #4 - Nov 3rd, 2010 at 3:43pm
Print Post  
Ok, it's a bit more complex than that. A visual object might not have any associated drawing, while its child visuals have ones. Here is a class that will cache the speified visual (Diagram in your case) and later render it when required:

Code
Select All
public class VisualCopy : FrameworkElement
{
	public VisualCopy(Visual visual)
	{
		drawing = new DrawingVisual();
		var dc = drawing.RenderOpen();
		Draw(visual, dc);
		dc.Close();
	}

	protected override void OnRender(DrawingContext drawingContext)
	{
		Draw(drawing, drawingContext);
	}

	private void Draw(Visual v, DrawingContext dc)
	{
		var tr = VisualTreeHelper.GetTransform(v);
		dc.PushTransform(tr);

		var dr = VisualTreeHelper.GetDrawing(v);
		if (dr != null)
			dc.DrawDrawing(dr);

		for (int i = 0, n = VisualTreeHelper.GetChildrenCount(v); i < n; ++i)
		{
			var c = VisualTreeHelper.GetChild(v, i) as Visual;
			if (c != null)
				Draw(c, dc);
		}

		dc.Pop();
	}

	private DrawingVisual drawing;
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
riemaecker
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 8
Joined: Jul 31st, 2009
Re: Preserve WPF's cached rendering
Reply #5 - Nov 8th, 2010 at 8:45am
Print Post  
This almost works. However, the layout of the copy misplaces all its elements. I am not sure why, but I'll look into the issue. Thank you!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint