Building a Basic User Control

A good way to get started with custom controls is to take a crack at creating a straightforward user control. In this section, we'll begin by creating a basic color picker. Later, you'll see how to refactor this control into a more capable template-based control.

Creating a basic color picker is easy—in fact, several examples are available online, one with the .NET Framework SDK and another with the Bag-O-Tricks custom control library that's provided by the WPF team. However, creating a custom color picker is still a worthy exercise. Not only does it demonstrate a variety of important control building concepts, but it also gives you a practical piece of functionality.

You could create a custom dialog box for your ...

Get Pro WPF in C# 2008: Windows Presentation Foundation with .NET 3.5, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.