Introduction to WPF

Preview:

DESCRIPTION

Introduction to WPF (Windows Presentation Foundation).

Citation preview

By: Munish Aroramunish.arora@gmail.com

WPF - Introduction

It is a new foundation for building Windows-based applications by using:

• Media

• Documents

• Application UI

What is WPF?

.NET Framework 4.0.NET Framework 4.0

Windows PresentationFoundation(WPF)

Windows PresentationFoundation(WPF)

Windows Communication Foundation(WCF)

Windows Communication Foundation(WCF)

Windows WorkflowFoundation(WF)

Windows WorkflowFoundation(WF)

Windows CardSpace(WCS)

Windows CardSpace(WCS)

WPF Architecture

WPF Core Components

PresentationFrameworkPresentationFramework

Common Language RuntimeCommon Language Runtime

PresentationCorePresentationCore

milcoremilcore

DirectXDirectXUser32User32

Managed Code

Unmanaged Code

Provides the presentation classes

that you use as a developer

Written in UnManaged code in order to enable tight integration with

DirectX. It renders each WPF element on a

DirectX surface

Low level API for handling user actions

Provides a managed wrapper for milcore and implements much of the underlying functionality

of WPF

DirectX enables all display handling in WPF, and

provides efficient hardware and software rendering

• WPF allows using both uses declarative language such as XAML and programming language (such has C#) to provide behavior

• When you add an element in XAML, the WPF runtime instantiates the object in the same way that you would programmatically instantiate an object in the code-behind file.

WPF

WPF Application Types

Stand-Alone Applications XAML Browser Applications (XBAPs)

You use this type of application when

you require access to system resources

You use this type of application when your

application can run with limited permission

In this demonstration, you will see how to

• Create a stand-alone WPF application

• Create a browser application

• Add controls to your application

Creating a Simple WPF Application

Standalone_Application

• Routed events are a new concept to most developers. In good old fashioned .NET 1.x/2.0, we all probably used some custom events or hooked some delegates onto some existing event, such as:

Routed Events

private System.Web.Forms.Button button1;button1.click+=new EventHandler(button1_Click);...private void button1_Click(object sender, EventArge e){ //Click Event seen, so something about it}

• When you create an application that has user interface, your application uses events to respond to user actions. E.g. when user clicks button, then it fires and event. So, corresponding code can be written to handle the events. These events thus define the behavior of application.

• In WPF the elements are arranged in hierarchical order known as element tree. e.g.

• Here StackPanel container control is inside the Windows element and Button controls are inside the StackPanel. Routed events are similar to events but their notification can move up or down the hierarchy tree.

Routed Events

• There are three types of event notification methods, namely:

– Bubbling: Allows events to bubble up the VisualTree (the tree of Visual UI Elements), to the root element.

– Tunneling: Allows events to tunnel down the VisualTree.

– Direct: Works just like the old .NET 1.x/2.0 CLR events. Only the subscriber gets to see the event. The one we see above is Direct event notification

Routed Events

• In this example, we will see how Routing works. Such that when button is clicked, the event goes to the container which may handle this.

– Steps:

• Add a StackPanel in the Grid

• Add buttons to stack panel

• Add a label in Grid

• Now add an EventHandler for click in StackPanel, such that when button is clicked, label should display that this button has been clicked

• Then we will add another button via code and check that if this newly added button is clicked, does it work in a similar way?

Routed Events - Example

Routed Events

• Let us create a XABP (XAML Browser Application)– Where-in you can browse from one page to other page and vice-versa

Navigation Capabilities

Example-XAML_BrowserApp

THANK YOU!

Recommended