In learning control templates, moving, resizing, and rotating from WPF Diagram Designer Part 1, the implementation of the Graphics designer's movement, size, and rotation is introduced, and the second section is to learn the features of design panels, thumbnails, frame-line rotation, and Toolbox.
WPF Diagram Designer-part 2
Design Panel (Designer canvas:variable size, scrollable)
In a designer that learns from the WPF Diagram Designer Part 1 The example of a control template, move, resize, and rotate, when you drag a design object outside the Designercanvas boundary, because Designercanvas has no scroll bars, We'll find that we can't find the object again. The easiest way to think of a solution is to add a scrollviewer to Designercanvas, but this solution won't solve the problem, because when you drag outside the canvas, you don't start to change the size of the canvas, so there's still no scroll bar, To solve this problem, we have to adjust the size of the canvas when designing objects move and resize.
The WPF control provides a meassureoverride allows the control to calculate the desired size and then returns to the WPF framework for layout. We can overload this method in Designercanvas to solve the problem mentioned above, the overloaded method is as follows:
Code
protected override size measureoverride (size constraint)
{
Size size = new size ();
foreach (uielement element in base. Children)
{
Double left = canvas.getleft (element);
Double top = canvas.gettop (Element);
left = double. isNaN (left)? 0:left;
top = Double. isNaN (top)? 0:top;
//measure desired size for each child
element. Measure (constraint);
Size desiredsize = element. DesiredSize;
if (!double. isNaN (desiredsize.width) &&!double. isNaN (desiredsize.height))
{
size. Width = Math.max (size. Width, left + desiredsize.width); The
size. Height = Math.max (size. Height, top + desiredsize.height);
}
}
//for Aesthetic reasons add extra points
size. Width = 10; The
size. Height = 10;
return size;
}
Note: When designing objects a lot, I guess there might be a performance problem. In ZOOMABLEAPPLICATION2:A million items that show an example of a millions object that can be used to solve this performance problem, let's leave a footprint here so that you can find