windows presentation foundation (wpf)ddwap.mah.se/tsfana/netiivb/wpf/lec5a_wpf.pdf · windows...

13
NET P i .NET Programming Windows Presentation Foundation (WPF) (WPF) Contents: WPF XAML WPF Controls Tools, Styles and XBAP Farid Naisan, [email protected]

Upload: vuongdang

Post on 12-Jul-2018

246 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Windows Presentation Foundation (WPF)ddwap.mah.se/tsfana/NetIIVB/WPF/lec5a_WPF.pdf · Windows Presentation Foundation (WPF) ... System.Windows.Markup XAML, ... Microsoft Exppggression

NET P i.NET Programming

Windows Presentation Foundation (WPF)(WPF)

Contents:• WPF• XAML• WPF Controls• Tools, Styles and XBAP

Farid Naisan, [email protected]

Page 2: Windows Presentation Foundation (WPF)ddwap.mah.se/tsfana/NetIIVB/WPF/lec5a_WPF.pdf · Windows Presentation Foundation (WPF) ... System.Windows.Markup XAML, ... Microsoft Exppggression

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.

Page 3: Windows Presentation Foundation (WPF)ddwap.mah.se/tsfana/NetIIVB/WPF/lec5a_WPF.pdf · Windows Presentation Foundation (WPF) ... System.Windows.Markup XAML, ... Microsoft Exppggression

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

Page 4: Windows Presentation Foundation (WPF)ddwap.mah.se/tsfana/NetIIVB/WPF/lec5a_WPF.pdf · Windows Presentation Foundation (WPF) ... System.Windows.Markup XAML, ... Microsoft Exppggression

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

Page 5: Windows Presentation Foundation (WPF)ddwap.mah.se/tsfana/NetIIVB/WPF/lec5a_WPF.pdf · Windows Presentation Foundation (WPF) ... System.Windows.Markup XAML, ... Microsoft Exppggression

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

Page 6: Windows Presentation Foundation (WPF)ddwap.mah.se/tsfana/NetIIVB/WPF/lec5a_WPF.pdf · Windows Presentation Foundation (WPF) ... System.Windows.Markup XAML, ... Microsoft Exppggression

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

Page 7: Windows Presentation Foundation (WPF)ddwap.mah.se/tsfana/NetIIVB/WPF/lec5a_WPF.pdf · Windows Presentation Foundation (WPF) ... System.Windows.Markup XAML, ... Microsoft Exppggression

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

Page 8: Windows Presentation Foundation (WPF)ddwap.mah.se/tsfana/NetIIVB/WPF/lec5a_WPF.pdf · Windows Presentation Foundation (WPF) ... System.Windows.Markup XAML, ... Microsoft Exppggression

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

Page 9: Windows Presentation Foundation (WPF)ddwap.mah.se/tsfana/NetIIVB/WPF/lec5a_WPF.pdf · Windows Presentation Foundation (WPF) ... System.Windows.Markup XAML, ... Microsoft Exppggression

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

Page 10: Windows Presentation Foundation (WPF)ddwap.mah.se/tsfana/NetIIVB/WPF/lec5a_WPF.pdf · Windows Presentation Foundation (WPF) ... System.Windows.Markup XAML, ... Microsoft Exppggression

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

Page 11: Windows Presentation Foundation (WPF)ddwap.mah.se/tsfana/NetIIVB/WPF/lec5a_WPF.pdf · Windows Presentation Foundation (WPF) ... System.Windows.Markup XAML, ... Microsoft Exppggression

Controls

A simple Calculator application using WPFp pp g

Wiring up events takes place as in Windows Form

11Farid Naisan

in Windows Form.

Page 12: Windows Presentation Foundation (WPF)ddwap.mah.se/tsfana/NetIIVB/WPF/lec5a_WPF.pdf · Windows Presentation Foundation (WPF) ... System.Windows.Markup XAML, ... Microsoft Exppggression

Another Examplep

12Farid Naisan

Page 13: Windows Presentation Foundation (WPF)ddwap.mah.se/tsfana/NetIIVB/WPF/lec5a_WPF.pdf · Windows Presentation Foundation (WPF) ... System.Windows.Markup XAML, ... Microsoft Exppggression

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