Tuesday, March 8, 2011

Controls in WPF (Code)

In the Windows Presentation Foundation, the term control is somewhat more specialized than in earlier Windows programming interfaces.

In Windows Forms, for example, everything that appears on the screen is considered a control of some sort. In the WPF, the term is reserved for elements that are user interactive, which means that they generally provide some kind of feedback to the user when they are prodded with the mouse or triggered by a keystroke. The TextBlock, Image, and Shape elements all receive keyboard, mouse, and stylus input, but they choose to ignore it. Controls actively monitor and process user input.

The Control class descends directly from FrameworkElement:

Object
--DispatcherObject (abstract)
------DependencyObject
--------Visual (abstract)
------------UIElement
------------------FrameworkElement
------------------------Control

Window derives from Control by way of ContentControl. Properties defined by Control include Background, Foreground, BorderBrush, BorderThickness, and font-related properties, such as FontWeight and FontStretch. (Although TextBlock also has a bunch of font properties, TextBlock does not derive from Control. TextBlock defines those properties itself.)

From Control descend more than 50 other classes, providing programmers with favorites such as buttons, list boxes, scroll bars, edit fields, menus, and toolbars. The classes implementing these controls can all be found in the System.Windows.Controls and System.Windows.Controls.Primitives namespaces, along with other classes that do not derive from Control.

No comments:

Post a Comment