Windows Presentation Foundation

Hello, WPF

WPF from Scratch
Navigation Applications
Content Model
Layout
Controls
Data Binding
Dependency Properties
Resources
Styles and Control Templates
Graphics
Application Deployment
Where Are We?

Layout

Introduction
Layout Basics
DockPanel
StackPanel
Grid
Canvas
Viewbox
Text Layout
Common Layout Properties
When Content Doesn't Fit
Custom Layout
Where Are We?

Controls

Introduction
What Are Controls?
Handling Input
Built-In Controls
Where Are We?

Data Binding

Introduction
Without Data Binding
Data Binding
Binding to List Data
Data Sources
Master-Detail Binding
Where Are We?

Styles and Control Templates

Introduction
Without Styles
Inline Styles
Named Styles
Element-Typed Styles
Data Templates and Styles
Triggers
Control Templates
Where Are We?

Resources

Introduction
Creating and Using Resources
Resources and Styles
Binary Resources
Global Applications
Where Are We?

Graphics

Introduction
Graphics Fundamentals
Shapes
Brushes and Pens
Transformations
Visual-Layer Programming
Video and 3-D
Where Are We?

Animation

Animation Fundamentals
Timelines
Storyboards
Key Frame Animations
Creating Animations Procedurally
Where Are We?

Custom Controls

Introduction
Custom Control Basics
Choosing a Base Class
Custom Functionality
Templates
Default Visuals
Where Are We?

ClickOnce Deployment

A Brief History of Windows Deployment
ClickOnce: Local Install
The Pieces of ClickOnce
Publish Properties
Deploying Updates
ClickOnce: Express Applications
Choosing Local Install versus Express
Signing ClickOnce Applications
Programming for ClickOnce
Security Considerations
Where Are We?

What Are Controls

What Are Controls?

Controls are the building blocks of an application's user interface. They are interactive features such as text boxes, buttons, or listboxes. You may be familiar with similar constructs from other user-interface technologiesmost UI frameworks offer an abstraction similar to a control. However, WPF is somewhat unusual, in that controls are typically not directly responsible for their own appearance. Many GUI frameworks require you to write a custom control when customizing a control's appearance. In WPF, this is not necessary: nested content, and templates offer powerful yet simpler solutions. You only need to write a custom control if you need behavior that is different from any of the built-in controls.

Many WPF user-interface elements are not controls. For example, shapes like Rectangle and Ellipse have no intrinsic behaviorthey are just about appearance.


Figure 3-1 shows how a control fits into a program. As you can see, the visible parts of the control are provided by its template, rather than the control itself. The control is not completely disconnected from these visuals, of course. It uses them to present information to the user. Moreover, since the visuals are all that the user can see, they will be the immediate target of any user input. This means that although visuals can be replaced, the replacement has certain responsibilitiesthere is a form of contract between the control and its visuals. The use of templates to replace visuals is discussed in Chapter 5.

Figure 3-1. A control's relationship with its visuals and data


You may be familiar with the Model View Controller (MVC) concept. This is a way of structuring the design of interactive systems. MVC has been interpreted in many different ways over the years, but broadly speaking, it always breaks the design down into objects representing the underlying data (the Model), objects that display that data (the View), and objects that manage input from the user and interactions between the model and view (the Controller).

MVC is a concept that can be used at many different scales, and it is somewhat unusual to apply it at the level of an individual control. However, if you are accustomed to the MVC way of looking at things, you may find it helpful to think of data binding as a way of attaching a Model, the visuals as the View, and the control as the Controller.


While the control makes itself visible to the user through its visuals, it makes its services available to developers mainly through an API, shown on the left of Figure 3-1. Controls offer commands to represent supported operations. For example, a text box might offer Cut, Copy, and Paste commands. Controls offer properties to provide a means of modifying either behavior or appearance. Controls raise events when something important happens, such as receiving some form of input. Finally, some functionality may be exposed through methods . Commands, properties, and events are preferred because they are easier to use from markup, and will be supported by design tools. However, for features that would only ever be used from code, methods may be a more appropriate form of API.

Of course developers and designers are not the only people who will use controls. Controls also need to respond to users, so let's look at how input is handled in WPF.


©2008 FAQ - WPF Labs - Discuss - Terms of Use - Privacy Policy - About WPF
- Interview Questions - Sharepoint Articles - Interview Questions Resource Library - All about LINQ - MS Knowledgebase Articles - Electronics and Hardware discussions