O'Reilly logo

Windows Presentation Foundation 4.5 Cookbook by Pavel Yosifovich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

Getting ready

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" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required