本文介绍了如何copyclone一个的UIElement并保持布局/呈现的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要复制一个复杂的数据绑定的UIElement ,但保持绑定,布局和显示的信息从原来的UIElement。

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

创建一个新的的UIElement 似乎效率不高,因为我会做另一个完整的绑定/测量/整理/渲染过程

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

到目前为止,我得到的最接近是创建一个新的 DrawingVisual ,打开它的渲染和使用源的UIElement DrawingGroup DrawDrawing。

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;

这是一个好方法,将其用于复杂的UI元素内边框工作(如大量的面板,定制控制等等等等)?

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

要给你一个背景下,我想提出一个 DocumentPaginator 这是运作良好,但提前inefficeintly由于相同的UI元素的娱乐。

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

谢谢,
皮特

推荐答案

如果它只是进行演示的目的,你可以使用的。更多信息可以发现,的和的。它甚至反映到连接的视觉所做的任何实时更新。

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.

这篇关于如何copyclone一个的UIElement并保持布局/呈现的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 16:51