2

I wish to copy a complex data-bound UIElement but keep the Binding, Layout and Rendering information from the original UIElement.

Creating a new UIElement seems inefficient since I would have to do another complete Binding/Measure/Arrange/Render pass.

The closest I've got so far is to create a new DrawingVisual, open it for rendering, and DrawDrawing using the source UIElement DrawingGroup.

DrawingVisual dv = new DrawingVisual();
DrawingGroup dg = VisualTreeHelper.GetDrawing(SourceElement);

using (DrawingContext dc = dv.RenderOpen())
{
     Drawing d = dg.Children[0];
     dc.DrawDrawing(d);
}

return dv;

Is this a good approach and will it work for complex UIElements (e.g. lots of Panels within Borders, custom Controls etc etc)?

To give you a context, I am making a DocumentPaginator which is working well, but inefficeintly due to the recreation of identical UIElements.

Thanks in advance, Pete

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Peter
  • 364
  • 5
  • 17

1 Answers1

0

If it's only for presentation purposes, you can use a VisualBrush. More information can be found here, here, and here. It even reflects any live updates made to the attached visual.

CodeNaked
  • 40,753
  • 6
  • 122
  • 148
  • Thanks for the advice, but I want to avoid the 'VisualBrush' for the very reason that it **does** reflect the changes to the attached visual. I want to be able to create a new 'UIElement' (or 'Visual') that uses the Source 'UIElement' info (time-taking layout and rendering info) to make an independent 'Visual' (that **does not** reflect changes to the SourceUIElement) – Peter May 05 '11 at 01:17