跨不同网格共享相同的FrameworkElement和DrawingVisuals实例(WPF.net 4)
我正在做一个应用程序,我用PathFigure,LineSegment。。。存储为FrameworkElement中的DrawingVisuals 我需要在2个不同的UI元素(网格或面板,无论什么…)中显示相同的图形 一个将由用户用于绘制,第二个将只允许可视化相同的绘制、缩放和滚动,而不影响第一个UI元素视口 我将有2000多个绘图图像,复制它们是愚蠢的 我目前正绞尽脑汁想办法解决这个问题。 在你看来,实现这一目标的正确解决方案是什么 更多信息: 我用一个简单的XAML尝试了显而易见的方法跨不同网格共享相同的FrameworkElement和DrawingVisuals实例(WPF.net 4),wpf,drawing,Wpf,Drawing,我正在做一个应用程序,我用PathFigure,LineSegment。。。存储为FrameworkElement中的DrawingVisuals 我需要在2个不同的UI元素(网格或面板,无论什么…)中显示相同的图形 一个将由用户用于绘制,第二个将只允许可视化相同的绘制、缩放和滚动,而不影响第一个UI元素视口 我将有2000多个绘图图像,复制它们是愚蠢的 我目前正绞尽脑汁想办法解决这个问题。 在你看来,实现这一目标的正确解决方案是什么 更多信息: 我用一个简单的XAML尝试了显而易见的方法 &l
<Grid>
<StackPanel>
<Border Name="B1" Background="Bisque" Width="400" Height="200"/>
<Border Name="B2" Background="Beige" Width="400" Height="200"/>
</StackPanel>
</Grid>
VdMap是一个框架元素
ElementVisual、StartElement和AddElement是我的内部功能。重要的是:
B1.Child = map; //I attach my Map to the border
B2.Child = map; //I try to attach the same FrameworkElement to the second border.
我得到运行时错误“指定的元素已经是另一个元素的逻辑子元素。请先断开它。”
看起来比我想象的要难。好的
我可能找到了正确的方法:VisualBrush和矩形
var mapClone = new VisualBrush { Visual = map };
rectangle = new Rectangle {
Width = 300, Height = 300,
Stroke = Brushes.Black, HorizontalAlignment = HorizontalAlignment.Left,
Fill = mapClone };
B2.Children.Add(rectangle);
我现在在B2中有一个可视的地图副本,可以分别缩放和变换
欢迎任何更好的想法。好的
我可能找到了正确的方法:VisualBrush和矩形
var mapClone = new VisualBrush { Visual = map };
rectangle = new Rectangle {
Width = 300, Height = 300,
Stroke = Brushes.Black, HorizontalAlignment = HorizontalAlignment.Left,
Fill = mapClone };
B2.Children.Add(rectangle);
我现在在B2中有一个可视的地图副本,可以分别缩放和变换
欢迎任何更好的想法