Adorners
The spec for this project states that the user can drag a cropping rectangle within any photograph and then click the Crop button to crop the photo, as shown in Figure 4-3.
To accomplish this, you'll need to be able to create and display a "rubberband" on mouse down and mouse drag, and leave it in place on mouse up (activating the Crop button)—and you'll need to be able to "crop" the photo to its new rectangle.
You'll implement the rubberband as an adorner. Adorners are, essentially, elements that are rendered "on top of" existing elements (or collections of elements). You can think of WPF as having what amounts to an acetate layer of adorners that can be laid on top of adorned elements, with the adorners positioned relative to the elements that are being adorned.

Figure 4-3. Cropping a photo
Adorners are often used to create element-manipulation handles (like rotation handles or resizers) or visual feedback indications. A rubberband for cropping is an excellent example. In fact, Microsoft offers sample code that you can "borrow" and adapt for the purposes of this application, as shown in Example 4-1.
Example 4-1. The rubberband adorner
using System;
using System.IO;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Documents;
namespace PhotoCooperative { public class RubberbandAdorner : Adorner { public Window1 Window { set; get; ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access