Creating a custom control
Before working with custom controls, you will need to know how to create custom controls and how to add them to any XAML pages. In this recipe, we will learn these basic operations first.
Getting ready
Let's open the Visual Studio IDE and create a new WPF application project, called CH05.SearchControlDemo
.
How to do it...
Perform the following steps to create your first custom control, which will contain a text input box and a button to build a search control. At the end, we will add it to the application window:
- Once the project has been created, right-click on the project, from
Solution Explorer
, and followAdd
|New Item...
from the context menu entries. A new dialog window will pop up on the screen.
- Inside the
Add New Item
dialog window, expand theInstalled
|Visual C#
|WPF
tree item, from the left navigation panel, and selectCustom Control (WPF)
from the right screen:

- Give the custom control a name (let's say,
SearchControl.cs
) and clickAdd
to create it. This...