Introduction to XAML and WPF

  • View

  • Download

Embed Size (px)

Text of Introduction to XAML and WPF

  • 1.Introduction to WPF Next Generation for Desktop Applications
    • Doncho Minkov
  • Telerik School Academy
  • Technical Trainer

2. Table of Contents

  • Windows Presentation Foundation (WPF)?
  • WPF basic features
  • WPF and other UI technologies
    • Windows Forms
    • DirectX
    • Silverlight
    • HTML + CS S
  • WPF classes
  • XAML basics

3. What is Windows Presentation Foundation? 4. What is Windows Presentation Foundation?

  • Windows Presentation Foundation (WPF)
    • An entirely new graphical display system for Windows
    • Empowers rich-media applications
    • Provides a clear separation between the UI (XAML) and the business logic (C#,VB.NET)
    • Influenced by modern display technologies such asHTML ,CSSandFlash
    • Hardware-accelerated

5. WPFB asicF eatures 6. V ectorG raphics

  • All WPF graphics areDirect3Dapplications
    • Direct3D(part of DirectX) is used in graphical applications where performance is important
    • Uses the video card hardware for rendering
    • The result: high-quality rich-media UI
  • Vector-based graphics allows to scale without loss of quality
  • WPF implements a floating-point logical pixel system and supports 32-bit ARGB color

7. R ichT extM odel

  • WPF includes a number of extremely rich typographic and text rendering features
    • Some of themwere not available inGDI
  • B uilding international fonts from composite fonts
  • WPF text rendering takes advantage ofClearTypetechnology
    • Use caching of pre-rendered text in the video memory
    • WPF has resolution-independent architecture

8. A nimation

  • WFP supports time-based animations
    • Presentation timers are initialized and managed by WPF
    • Scene changes coordinated by using astoryboard
  • Animations can be triggered
    • By other external events
      • Including user action
  • Animation can be defined on a per-object basis directly from the XAML markup

9. A udio andV ideoS upport

  • WPF can incorporate audio and video into a user interface
  • Audio support in WPF is a thin layer over the existing functionality in Win32 and WMP
  • WPF supports the video in formatsWMV, MPEGand someAVIfiles
  • Relationship between video and animation is also supported
    • They are both ways of showing moving images
    • Animation can be synchronized with media

10. S tyles andT emplates

  • In WPF astyleis a set of properties applied to content used for visual rendering
    • Similar to the concept of CSS
    • E.g. setting the font weight of aButton control
  • Use them to standardizenon-formattingcharacteristics
  • WPF styles have specific features for building applications
    • Ability to apply different visual effects based on user events

11. S tyles andT emplates(2)

  • T emplatesin WPF allow you to fully change the UI of anything in WPF
  • K inds oft emplates available within WPF
    • ControlTemplate
    • ItemsPanelTemplate
    • DataTemplate
    • HierarchicalDataTemplate

12. C ommands

  • Commands are more abstract and loosely-coupled version of events
    • Examples: copy, cut, paste, save, etc.
  • WPF support for commands reduces the amount of code we need to write
  • It gives us more flexibility to change the UI without breaking the back-end logic
  • Commands have action, source, target and binding

13. C ommands(2)

  • The power of commands comes from the following three features
    • WPF defines a number of built-in commands
    • Commands have automatic support for input actions
    • Some WPF controls have built-in behavior tied to various commands
  • Commands are intended to do two things:
    • Check whether an action is available
    • Execute an action

14. D eclarative UI with XAML

  • WPF introduces a new XML-based language for describing UI elements known asXAML
    • XAML=eXtensible Application Markup Language
  • XAML is a completely declarative language
    • A declarative language says "what"
    • An imperative language says "how"
  • XAML describes the behavior and integration of components (in most cases UI components)

15. O bject- B asedD rawing

  • At the lower-level WPF works in terms ofshapes , not in terms of painting pixels
    • Shapesare vector-based and can easily scale
  • Developers createshapeobjects and let WPF maintain the display in the most optimized way
    • WPF provides a number of ready-to-use shape objects like line, rectangle, ellipse, path, etc.
  • Shape objects can be used inside panels and inside most WPF controls

16. WPFa ndO ther UIT echnologies 17. Windows Forms

  • Windows Forms is the culmination of the display technology built onGDI+ and User32
    • Its more mature than WPF
    • Has solid limitations
    • No separation between UI and the C# code
  • WPF is the platform for the future of Windows development
    • Based on DirectX and Direct3D
    • Separation between the UI and C# code

18. DirectX

  • WPF create multimedia applications with real-time graphics
    • Such as complex physics-based simulators or cutting-edge action games
  • WPF applicationsareDirectX applications
    • As a result, even the most mundane business applications can use rich effects andantialiasing
  • WPF graphics is entirely vector-based
    • This allows zoom-in / soom-out with no loss of quality

19. Silverlight

  • Silverlightis a cross-platform, cross-browser plugin, which contains WPF-based technology
    • Rich Internet Application (RIA) platform
    • Including XAML and subset of WPF
    • Provides rich-media features such as video, vector graphics, and animations
  • Silverlight and WPF share the XAML presentation layer
    • Both technologies are similar, but Silverlight is limited in many aspects

20. HTML + CSSvs. XAML + Styles

  • Cascading Style Sheets (CSS) is astylesheetlanguage
    • Used to describe the presentation of information in HTML documents
  • XAML elements haveStyleproperty
    • Similar to CSS (as a concept)
  • The HTML and XAML are tag based systems to describe UI
    • XAML is more powerful in many aspects

21. XAML Basics 22. XAML Basics

  • XAML is an XML-based language for creating and initializing .NET objects
    • Its used in WPF as ahuman-authorableway of describing the UI
    • Used to separate the UI from the C# code
  • XAML contains a hierarchy of elements representing visual objects
    • These objects are known as user interface elements or UI elements

23. Elements and Attributes

  • UI elements have a set of common properties and functions
    • Such asWidth ,Height ,Cursor , andTagproperties
  • Declaring an XML element in XAML
    • Equivalent to instantiating the object via aparameterlessconstructor
  • Setting an attribute on the object element
    • Equivalent to setting a property of the same name

24. XAML Basics - Example

  • Constructs button with caption "OK"

OK 25. Example E xplanation

  • The root element,Windowis used to declare a portion of a class