The .NET Framework comes with a plethora of built-in controls that cover most real-world scenarios. And when we need something slightly different, we have seen that we can utilize the WPF styling and/or templating systems to adapt them to our requirements. However, there are also further ways of adjusting the built-in controls to suit our needs.
Each .NET control has a number of methods, each named with the prefix On, for example, OnInitialized, or OnApplyTemplate. These are protected methods, that can be overridden in any custom class that extends a .NET control. They are called at certain points in the control's lifetime and enable us to change the default behavior of each control.
They enable us to do things as simple as starting a process as soon as a control has been initialized, or accessing a named control from a custom ControlTemplate, once it has been applied. But they can also be used to completely change the default behavior, or the look and feel of the control. In this chapter, we will investigate these methods and give examples of how they can be utilized to our advantage.
We will then examine further ways of customizing the built-in controls, by adjusting their default ControlTemplate and leveraging new uses from them, while maintaining or extending their existing functionality. In this chapter, we consider the built-in controls merely as a starting point for our requirements, and learn how to build upon them, keeping what we need and changing what we don't.