There is a graphics WPF editor that is designed to work with diagrams. Because diagram can consist of very large number of objects, it was chosen to use Drawings for output. That means we create list of some business objects
class BusinessObject
{
// bunch of other properties and methods
public GeometryDrawing MyDrawing {get;set;}
}
pass it to helper that creates DrawingVisual for each drawing :
public List<Visual> BuildVisuals(List<BusinessObject> objectsList)
{
// foreach item in objectsList takes item.MyDrawing and draws it with DrawingContext
}
and then inject received data into drawing host
public class VisualHost : FrameworkElement
{
// FrameworkElement overrides, skipped
public readonly VisualCollection _children;
public VisualHost(List<Visual> visualsList)
{
_children = new VisualCollection(this);
foreach(var visual in visualsList)
{
_children.Add(visual);
}
// mouse handlers, other logic (skipped)
}
}
Everything works fine and quickly (even VisualHitTesting with backward mapping to respective business object with two-way data changing on-the-fly), but now there is a need to allow visual editing of objects – moving them around workspace, change size, scale ratio, etc. WPF Thumbs and Adorners come into mind (http://www.codeproject.com/KB/WPF/WPFDiagramDesigner_Part1.aspx), but they are intended to work with UIElement/Controls, that our Visuals aren’t. Does anyone see a way to solve this problem without much changes of initial logic? Some workarounds or similiar functionality maybe. Rewriting the above mentioned code is not an option, we can’t have 1000+ Control objects in memory if we use them on diagram. Thanks in advance.
Problem was solved manually – resizing and rotating adorners were drawn as separate objects over existing ones and added/removed from canvas on set/lost focus.