NET P i.NET Programming
Windows Presentation Foundation (WPF)(WPF)
Contents:• WPF• XAML• WPF Controls• Tools, Styles and XBAP
Farid Naisan, [email protected]
Why WPF?y
APIs from .NET 2.0 are merged into WPF as of .NET g3.0
The API are still supported The API are still supported
.NET 2.0 APIs Included in WPF.NET 2.0 APIs Included in WPFForms and controls Windows.Forms2D graphic GDI+3d graphic DirectXVideo streaming Windows Media PlayerFl l P i i l i f PDF Flow-style documents
Programmatic manipulation of PDF files
Separate UI from code using XAML2Farid Naisan
Separate UI from code using XAML.
WPF Application Stylespp y
WPF can be used to build a variety of GUI styles.y y
Traditional Desktop ApplicationsS Similar to Windows Forms
Navigation-based applications Similar to browser-based web applications
Browser-hosted applications (XBAP)pp ( ) Is downloaded from a given URL and installed on the local
computer
Has *.xbap extension,
Supported by IE 6 and later and Firefox.
3
pp y
Farid Naisan
Silverlightg
Is a cross-platform plug-in for building browser-based p p g ginteractive applications.
The foundation for Sliverlight is provided by WPF and The foundation for Sliverlight is provided by WPF and XAML.
Silverlight can be used to build feature rich and Silverlight can be used to build feature rich and interactive web applications
V t b d hi l t Vector-based graphical system
Animation support
Multimedia support
Rich text document model4
Rich text document model
Farid Naisan
WPF Assemblies
For any type of WPF the assemblies required are:y yp q
PresentationCore.dll
PresentationFoundation.dll
WindowsBase dll WindowsBase.dll The assemblies must be referenced by your WPF
application.
Done automatically by Visual Studioy y
5Farid Naisan
WPF Namespacesp
System.Windows Types such as A li i
Required by all WPFli iApplication,
Windowapplications
Systems.Windows.Controls WPF controls Controls, menus,layoutmanagers
System.Windows.Markup XAML, BAML BAML is the equivalent binary format of XAMLbinary format of XAML
System.Windows.Media Animations,3D, text, multimedia
Root namespace to severalsub-namespaces
S t Wi d N i ti N i ti l i Al f d ktSystems.Windows.Navigation Navigation logic for XBAPs
Also for desktop applications that require navigation page model
Systems.Windows.Shapes 2D graphic
6Farid Naisan
XAML
XAML is based on XML used for structuring objects.g j
Every XAML element maps to a class in the .NET Framework.Framework.
The root element in every XAML document is the name WindowWindow.
7Farid Naisan
Tools
Microsoft Expression Blend is for designing UI for Web p g gand desktop applications based on XAML for WPF and Silverlight
XamlPad – provides real-time display of XAML markup.
Visual Studio 2008 and later Visual Studio 2008 and later
MSBuild.exe is used to build XAML code into the blassembly.
8Farid Naisan
XAML Elements and Attributes
Populate the root element with a child element Populate the root element with a child element. The child element is one of the panel types.
Each XAML element maps to a .NET class or structure.
Continue with additional UI elements Buttons, TextBoxes, Labels, etc.
Assign Assignattributes
9Farid Naisan
The Windows Class
The Window class does not contain a container to allow drawing controls directly on it.
It needs a container to host other controls It needs a container to host other controls.
Grid is the default container when using VS.
10Farid Naisan
Controls
A simple Calculator application using WPFp pp g
Wiring up events takes place as in Windows Form
11Farid Naisan
in Windows Form.
Another Examplep
12Farid Naisan
Summaryy
WPF is a new API to build desktop applications that p ppintegrates various APIs into a single object model:
2D Graphics 2D Graphics
3D Graphics
Audio, Video
It also separated different concerns via a new markup p planguage XAML:
Design of GUI separated from CodeDesign of GUI separated from Code
Programmer’s concern separated from designer’s
13Farid Naisan