Вы находитесь на странице: 1из 42

Introducing

Windows Presentation
Foundation
By
Pradeep
Agenda
Introduction to .NET Framework 3.0
What is WPF?
What is XAML?
WPF application types
WPF controls
Using WinForms(.Net 2.0) controls in WPF
Styles
Benefits of WPF
Drawbacks of WPF
Tools for application development
Microsoft .NET Framework 3.0
Framework 3.0 = .NET Framework 2.0 + 4 new technologi

The application
development
framework for
Windows Platform
Microsoft .NET Framework 3.0

The .NET Framework 3.0 is included with


Windows Server 2008 and Windows Vista.
It can also be installed on Windows XP and the
Windows Server 2003 operating systems.
Windows Presentation Foundation

New technology for


building User Interface
applications in .NET
Framework 3.0
Windows Presentation Foundation
It enables you to build UI that can handle
media content including
2D and 3D graphics,
vector-based graphics,
animation,
speech, audio and video.

A UI element in WPF consists of


two parts:
Mark-Up code - XAML (User
Interface)
Code - C# or VB.Net
(Application logic)
XAML
XAML stands for Extensible Application Markup Language.
XAML is an XML based markup language for creating user
interfaces for .NET applications. 
Every XAML code must be a well-formed XML file and XAML
inherits all XML definitions and rules. 
Every XAML element maps to a .NET CLR class. 
XAML attributes map to CLR properties and events.
XAML files can be rendered in the browser / stand alone
application.
XAML separates the UI from the code behind application logic.
XAML files will have the extension “.XAML”. Ex: App.xaml
XAML File..

< Back
Application types in WPF
Supports two types of applications:

Windows Application—Hosted in a window and has


full access to system resources.

XAML Browser Application—Deployed on a server


and accessible through browser.
This application type runs in the Internet zone, which
limits its access to system resources.
WPF Windows App. Project
Structure
XBAP Application Project Structure
App.Xaml

App.xaml declares the application


starting point.
It is used to
Set the initial XAML file to be loaded – Startu
Define application level styles.
Handle application level events.
App.xaml

< Back
WPF Controls

Supports a rich set of controls.


Custom controls.
User controls.
Windows Forms controls can be used.
Namespace – System.Windows.Controls
Few standard controls available in .NET
2.0 are missing.
WPF Controls

WPF controls can be grouped


into following categories:
Layout/Panel controls User
Buttons Information
UI Navigation
Menus
Editing
List Selection
Media
Range Selection
Digital Ink
Layout/Container controls

A WPF Window can hold only a single


element.

To add more than one element use a


container control.

WPF container controls derive from


System.Windows.Controls.Panel class.
Layout controls
Grid: Child controls are arranged in rows and columns.

StackPanel: Child controls are stacked either vertically or


horizontally.

WrapPanel: Child controls are positioned in left-to-right


order and wrapped to the next line when there are more
controls on the current line than space allows.

Canvas: enables absolute positioning of controls.

DockPanel: Child controls are aligned to the edges of the


panel.
Buttons

Button
RadioButton
RepeatButton
ToggleButton – Two states Pushed & UnPushed
Menus

Menu
ToolBar
ContextMenu
List Selection

ComboBox
ListBox
TreeView
User Interface Navigation

ScrollBar
TabControl
Thumb
Frame
User Information

Expander
Label
TextBlock
Popup
ProgressBar
StatusBar
ToolTip
Editing

TextBox
RichTextBox - Display text in paragraph,
in table format,View images, enable spell
check
Media

Image
MediaElement
<MediaElement
Source=“media\JabWeMet.wmv"
Width="450" Height="250" />
WPF Controls

Range Selection
Slider
Dialog Boxes
PrintDialog
Missing controls
Color Dialog LinkLabel
DataGridView MaskedTextBox
BindingNavigator MonthCalendar
DateTimePicker NotifyIcon
ErrorProvider PageSetupDialog
FolderBrowserDi PrintDocument
alog PrintPreviewDialo
FontDialog g
HelpProvider PropertyGrid
ImageList
Hosting Windows Forms control in
WPF
Use WindowsFormHost control to host windows
forms control.

Add a reference to WindowsFormsIntegration.dll.

Assign the Windows Forms control to the Child


property of the WindowsFormHost control.
Sample code..

<<
BACK
Styles

Style is a set of properties applied to


change the look and feel of an element.
Styles can be used in two ways:
Inline Styles
Named Styles
Inline Styles

Stylable elements have Style


property which can be set inline.
Named Styles

Create a style within the Resource


section, give a name to the style and
apply the style by name.
Triggers

WPF styles support triggers, which


allow you to change the style of a
control when another property is
changed.
Shapes

WPF supports a rich set of Shape objects.


Available shape objects include
Rectangle
Ellipse
Line
Path
Polygon
PolyLine
All shape objects inherit from Shape class.
Brushes
SolidBrush – paints an area with solid color. Link

LinearGradient Brush - paints an area with multiple


colors that blend into each other . Link

RadialGradientBrush – Gradient radiates out from the


center. Link

ImageBrush – paints an area with an image. Link

DrawingBrush - paints an area with a Drawing, which


can include shapes, text, video, images, or other
drawings . Link

VisualBrush – paints an area with the visual content of


an element. Link
Brushes Example

<< Back
WPF Application Compilation
Application – MainWindow.xaml,
MainWindow.xaml.cs
Phase-1 – XAML Compilation
1. XAML file will be converted to BAML file by XAML compiler.
2. [ MainWindow.xaml  MainWindow.baml ]
3. BAML file will be placed in obj/Debug or obj/Release folder.
4. Partial class will be generated – MainWindow.g.c
Phase-2 – Class Compilation
1. MainWindow.xaml.cs and MainWindow.g.c will be compiled into an
assembly by language compiler – csc.exe.
2. BAML files are embedded as resource files in the assembly.
Benefits
Browser support.
Relatively easy to understand XAML.
Allows separation of UI design from
implementation - Markup/Code behind model.
Easy to create 2D and 3D animations in UI.
Rich UI.
Benefits – Continued..
WINFORMS WinForms PDF WinForms + Windows Media Direct3D WPF
GDI Player
Forms, Controls X X X

Complex text X X

Images X X

Video / Audio X X

2D Graphics X X

3D Graphics X X
Drawbacks

Few standard controls available in


.NET 2.0 are missing.
Steep Learning curve.
Performance impairment – extensive
use of System resources.
Development tools
.NET Framework 3.0/3.5
Visual Studio 2008.
Visual Studio 2005 with extension for WPF
Intellisense
Compilation feature
XamlPad
Microsoft Expression (Suite of tools)
Questions and Answers

Вам также может понравиться