Introducing WPF Controls Features

Before using WPF controls, you need to understand some behaviors. In Chapter 31, “Creating WPF Applications,” you learned that UI elements, including controls, are generally declared in XAML code. You also saw how to assign a name to controls to interact with them in Visual Basic code. XAML allows declaring and implementing controls even if you do not assign a name. For example, the following Button declaration is legal:

<Button Width="100" Height="50" Click="OnClick"/>

The control declared in this way works normally as you would expect, also raising click events that you can handle in managed code. This is possible because of the particular WPF architecture part that implements routed events discussed in Chapter 31. When an unnamed control raises an event, the event passes through the entire Visual Tree, and the WPF runtime can intercept the event independently from the control name. Providing a name therefore is useful when you need to assign properties in managed code or when you want to assign an event handler to a specific visual element. Another interesting feature is that WPF controls are generally defined as lookless. This means that WPF controls are classes that expose a series of properties defining the behavior of controls while the look is assigned via a template. Basically when you drag a WPF control from the toolbox to the designer, the control takes advantage of a standard template that defines its layout, but templates can be completely customized or overridden with the so called control templates. Chapter 33, “Brushes, Styles, Templates, and Animations in WPF,” provides more examples and explanations, but you need to understand the concept before examining common controls. Basing controls’ layout on templates allows roles separation between developers and designers and is the reason why Microsoft created a tool such as Expression Blend. Another fundamental feature in WPF control is that it can contain almost any visual elements. This is possible with the ContentControl item that is the subject of next section.

WPF Controls and Silverlight Controls

Understanding WPF controls is useful for Silverlight development, too. In most cases you notice that controls described here have a counterpart in Silverlight, and this is the reason why a similar discussion is not done for Silverlight.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.146.61