WPF Introduction
WPF Introduction
Foundations)
Introduction to WPF
Create desktop applications for Windows
Resolution-independent and vector-based rendering
engine
Develop an application using Markup and code-behind
2D and 3D graphics, animations
Rich composition and customization
You can create a ComboBox filled with animated Buttons or a
Menu filled with live video clips!
WPF Architecture
The presentation framework and
the presentation core have been
written in managed code.
Milcore is a part of unmanaged
code which allows tight integration
with DirectX (responsible for
display and rendering).
CLR makes the development
process more productive by
offering many features such as
memory management, error
handling, etc.
Markup and Code-behind
Use XAML markup to implement the appearance of an
application
Use code-behind to implement its behavior.
Following benefits:
Development and maintenance costs are reduced because
appearance-specific markup is not tightly coupled with
behavior-specific code.
Development is more efficient because designers can
implement an application's appearance simultaneously with
developers who are implementing the application's behavior.
Globalization and localization for WPF applications is
simplified.
XAML
Extensible Application Markup Language
Pronounced as “Zammel”
XAML is an XML-based markup language
Declarative language
Use to implement application's appearance
Create windows, dialog boxes, pages, and user
controls, and to fill them with controls, shapes, and
graphics.
Case Sensitive
XAML Example
The following example uses XAML to implement the
appearance of a window that contains a single button:
Information Description
<Window It is the opening object element or
container of the root.
x:Class = "Resources.MainWindow" It is a partial class declaration which
connects the markup to the partial
class code defined behind.
xmlns = Maps the default XAML namespace
"http://schemas.microsoft.com/win fx for WPF client/framework
/2006/xaml/presentation"
xmlns:x = XAML namespace for XAML
"http://schemas.microsoft.com/w infx language which maps it to x: prefix
/2006/xaml"
> End of object element of the root
</Window> Closing the object element
Code-behind
Implement the functionality
Responds to user interactions
Handling events (for example, clicking a menu, tool
bar, or button)
Calling business logic and data access logic in
response
Written in C# or VB.NET
Code-behind Example
Basic XAML Syntax
<Button></Button>
Or
<Button />
<Button>A button</Button>
Or
<Button Content="A button" />
Property Elements
Instead of the property being specified as an attribute
within the element tag, the property is specified using
an opening element tag
in elementTypeName.propertyName form, the value of the
property is specified within, and then the property
element is closed.
<Button FontWeight="Bold">
<WrapPanel>
<TextBlock Foreground="Blue">Multi</TextBlock> <TextBlock
Foreground="Red">Color</TextBlock>
<TextBlock>Button</TextBlock>
</WrapPanel>
</Button>
Code vs XAML
XAML is pretty short and concise for describing
interfaces.