Friday, June 11, 2010

Choose a base class for our own control

Choosing the right base class is crucial and can save a lot of time! Compare the features of your control with existing controls and start with one that matches close. The following list should give you a good overview from the most leightweight to more heavyweight base types:

•UIElement - The most lightweight base class to start from. It has support for LIFE - Layout, Input, Focus and Events.

•FrameworkElement - Derives from UIElement and adds support for styling, tooltips and context menus. It is first base class that takes part in the logical tree and so it supports data binding and resource lookup.

•Control - is the most common base class for controls (its name speaks for itself). It supports templates and adds some basic properties as Foreground, Background or FontSize.

•ContentControl - is a control that has an additional Content property. This is often used for simple containers.

•HeaderedContentControl - is a control that has an Content and a Header property. This is used for controls with a header like Expander, TabControl, GroupBox,...

•ItemsControl - a control that has an additional Items collection. This is a good choice for controls that display a dynamic list of items without selection.
•Selector - an ItemsControl whose items can be indexed and selected. This is used for ListBox, ComboBox, ListView, TabControl...

•RangeBase - is the base class for controls that display a value range like Sliders or ProgressBars. It adds an Value, Minimum and Maximum property.

No comments:

Post a Comment