Creating custom controls
When using WPF, we can generally create the UI that we want using the many techniques already discussed in this book. However, in the cases when we require a totally unique control with both a custom drawn appearance and custom functionality, then we may need to declare a custom control.
Developing custom controls is very different to creating UserControl
elements and it can take some time to master this. To start with, we will need to add a new project of type WPF Custom Control Library to declare them in. Also, instead of having a XAML page and a code behind file, we only have the code file. At this point, you may be wondering where we define what our control should look like.
In fact, when defining a custom control, we declare our XAML in a separate file named Generic.xaml
, which is added by Visual Studio when we add our controls project. To clarify, the XAML for all of the custom controls that we declare in this project will go into this file. This does not relate...