Before you write a custom control, the first question you need to ask is, do I really need a custom control? A primary reason for writing a custom control is that the user interface technologist can modify the appearance of the control, but as we've seen in the previous chapters, content models and templates mean that this is usually unnecessary. WPF provides an advanced, scaled customization technology that you should keep in mind-when considering writing a custom control.
To modify the appearance of an existing control by using a property
Combine some existing controls
Embed content into existing controls
Replace an existing control with a template
Create a custom control or other custom element
This order provides an incremental level of competency to exchange for minor additional effects at each level. In these simple situations, you can adjust the behavior and appearance of an inline control to suit your needs by setting the properties. The next step is to compile the controls together to form a more powerful whole. You can take this composition to the next step by embedding the content in another control. You can use a template to completely replace the appearance, as described in chapter 5th. Once technology 1-4 doesn't meet your needs, writing a custom element is like a custom control that looks like an answer.
Whether you need to write a new visual element type, an important indication is whether you plan to add a new API feature. Even in this case, you should carefully consider which custom element type to write, and the control is not the only element kind. You can get more flexibility by writing an underlying component and integrating it into the appearance of a known control. For example, a large number of elements that make WPF flexible, such as layout classes and shapes, are derived from FrameworkElement and are not actually controls-they are not derived from the control base class.
If you decide on a custom element to make the best approach, you need to do a lot of design steps. First, you have to pick out the base class. Does it derive from Frameworkelement,control, or one of the other base types provided by WPF? Then you have to define the API to determine which attributes, events, and commands your component has. Finally, if your new element provides the same elasticity as the inline component, you need to be aware of the interface between the element and its template.