Learn from WPF Diagram Designer Part 2 learning panels, thumbnails, border selection, and toolbox

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.