Introduction to WPF
WPF is a radical departure from the established way of building Windowsbased apps
Subindev P
What we will cover in this session
Introduction to WPF
What is WPF ? Why WPF ? Architecture WPF Graphics Model WPF Development Introduction XAML Element Composition Deployment Security
What is WPF
A productive, unified approach to UI, media and documents to deliver unmatched UX. Not only about UI Controls. Introduced a new programming model.
.NET Framework 3.0
.NET Framework 3.0 (formerly WinFx)
NET Framework 2.0 + 4 new technologies
C# 2.0 VB.NET 2005 J# 2.0 C++ XAML
ASP.NET 2.0
Win Forms 2.0
WCF
WF
WPF
Card space
Base Class Libraries 2.0
Common Language Runtime 2.0
The Code Names
.NET Framework 3.0 (WinFx)
Windows Presentation Foundation (Avalon) Windows Communication Foundation (Indigo) Windows Workflow Foundation Windows CardSpace (InfoCard)
WPF Flavours
WPF
Windows Application
Runs on the client desktop Equivalent to a Windows Forms Application
XAML Browser Application (XBAP)
Runs in the browser Limited security context (WPF requires at least .NET 3.0 installed on the client)
Silverlight
Cross browser, Cross Platform plug-in for creating rich internet applications
Why WPF?
With all the existing UX technologies what does WPF give us?
Limitations of existing technologies
Not taking full advantage of hardware capabilities Pixel size dependent
Poor experience on very high or very low DPI displays
Implementation difficulty can be a huge barrier to pleasing and efficient user experience Etc
Advantage WPF
Greater hardware capabilities used Declarative programming XAML Integrated Platform Powerful features
Developer-Designer workflow Many Tools emit XAML
Images, Audio, Video, 3D, Documents
Data binding, Styles, Triggers, Control Template, Dependency Properties, Routed events & commands
Interoperability Win forms Win32
Demo
WPF Architecture
.NET DirectX Graphics pipeline of WPF
presentationcore
milcore
WPF Graphics Model
Coordinate System
Coordinate system is basically the same as in GDI
0,0 is top left of coordinate space Y-axis points down, X-axis points right Coordinates are doubles in WPF instead of integers Z-index by default is applied from bottom to top in the order of the elements in the visual tree. Panel.ZIndex allow this behavior to be changed.
Vector Based Graphics
Vector graphics are graphics defined by line and curve segments rather than a bit map of colors Resolution independence Allow for full scalability
High Quality Rendering
Resolution Independence
WPF uses Device Independent Pixels
All elements in a WPF application will scale correctly based on DPI settings. A DIP is defined as 1/96th of a screen inch
WPF Development Introduction
How do you build WPF Applications?
WPF Application Model
XAML-based User Interface Managed code behind Application Class
Demo
XAML
eXtensible Application Markup Language Declarative markup language for UI design If you learn XAML, then you can program UI in, WPF Silverlight WP7 WinRT
XAML, cont.
XML-based serialization format for CLR objects
Eg. Class Property Event : Button : Height, Background : b_Click
<Button Height=100 Background=Red Click=b_Click />
XAML, cont.
Xaml compiler compiles XAML into BAML BAML is a binary representation of the XAML optimized for runtime loading. The compiled BAML is embedded into the resources of the assembly.
XAML, cont.
Any CLR namespace can be mapped into XAML:
<Window xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:my='clr-namespace:MyClrNamespace;assembly=MyAssembly>
XAML can also be used for things other than WPF UI declaration.
For example: Windows Workflow uses XAML to describe their workflows. (They call it XOML).
Managed Code
When compiled, the XAML file is used to generate a code file
Eg. Window1.g.cs Partial class
XAML files can be paired with managed code-behind files which are also marked as partial classes.
Partial classes are a feature of the .NET Framework 2.0
Application Class
The Core of the WPF Application Model Application Message Dispatching Provides Application Events Application
Application.Run method
Serves as a container for WPF applications Allows data to be shared across pages
Supports Navigation Between Pages
Lifetime: Activated, Current, Deactivated, Dispatch erUnhandledException, Exit, Run, SessionEnding, Shu tdown, ShutdownMode, Startup.
Note :- We can create a WPF application without Application class. But XBAP required one.
Element Composition
Element composition is at the heart of WPFs user interface model An element may contain one or more child elements, which in turn, may contain additional elements
Composed elements form a hierarchy known as an element tree
Demo
Deployment
ClickOnce Deployment
A .NET Framework 2.0 Technology
Preferred method of deployment for WPF applications
Both installed and browser-hosted
The application is published on a server
A deployment manifest is used to specify the deployment parameters
Version checking/updating occurs each time the application runs
MSI Deployment
WPF applications can also be deployed using a traditional MSI-based installation routine
Security
Full Trust Applications
Installed applications run with full trust Have complete access to system resources If installed through ClickOnce, the user is prompted for authorization
Similar to Win32 applications
Partial Trust Applications
Browser applications run with partial trust Have limited access to system resources If installed through ClickOnce, the user is not prompted for authorization
Cannot compromise system security
With Internet Zone permissions
Development Tools
Visual Studio Expression Suite XamlPad (SDK Tool) Perforator (SDK Tool) Snoop - http://www.blois.us/Snoop/ Kxaml
Thank You