Creating a lightweight custom element
Custom controls provide a way to create a user interface based on XAML elements. Sometimes, however, a more complex UI is required, that cannot be easily achieved by XAML alone, or where low level control is desired. In such cases, we can create a lightweight element, deriving from
FrameworkElement that does its own drawing without creating any particular element. This makes the control consume less memory and WPF layout logic does not need to consider many elements.
In this recipe, we'll take a look at the way to implement such lightweight elements.
Make sure Visual Studio is up and running.
How to do it...
We'll create a simple bar graph control to demonstrate the ability to draw in a more "manual" ...