12
By: Munish Arora [email protected] WPF - Introduction

Introduction to WPF

Embed Size (px)

DESCRIPTION

Introduction to WPF (Windows Presentation Foundation).

Citation preview

Page 1: Introduction to WPF

By: Munish [email protected]

WPF - Introduction

Page 2: Introduction to WPF

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)

Page 3: Introduction to WPF

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

Page 4: Introduction to WPF

• 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

Page 5: Introduction to 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

Page 6: Introduction to WPF

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

Page 7: Introduction to WPF

• 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}

Page 8: Introduction to WPF

• 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

Page 9: Introduction to WPF

• 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

Page 10: Introduction to WPF

• 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

Page 11: Introduction to WPF

• 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

Page 12: Introduction to WPF

THANK YOU!