Overview of WPF - PowerPoint PPT Presentation

1 / 28
About This Presentation
Title:

Overview of WPF

Description:

Overview of WPF Ivan Krivyakov Senior Managing Consultant SunGard Consulting Services ... it has almost mathematical beauty New approach to UI programming: ... – PowerPoint PPT presentation

Number of Views:51
Avg rating:3.0/5.0
Slides: 29
Provided by: ikrivComde
Category:

less

Transcript and Presenter's Notes

Title: Overview of WPF


1
Overview of WPF
  • Ivan Krivyakov
  • Senior Managing Consultant
  • SunGard Consulting Services
  • E-mail
  • Ivan.Krivyakov_at_SunGard.com
  • ivan_at_ikriv.com
  • http//www.ikriv.com/demo/wpf/

2
Overview of WPF
  • What Is This Presentation About
  • WPF for an experienced developer
  • What makes WPF different?
  • Things to explore
  • Definitely not a tutorial

3
Overview of WPF
  • Why Is WPF Important?
  • Its a major technology from a big market player
  • It is gaining ground in replacing Windows Forms
  • Many clients start including WPF knowledge as a
    requirement for hire
  • Officially released in Nov 2006 and still popular
    definitely not a hype bubble

4
Overview of WPF
  • A Contrived Mixture Formula
  • WPF
  • XAML
  • Data Binding
  • Styles

5
Overview of WPF
  • XAML
  • XML-based object definition language
  • Defines objects and their properties
  • Similar to the language of Spring.Net
  • Primarily used to describe UI artifacts
  • Can describe almost any .NET type
  • Limited support of generics

6
Overview of WPF
  • XAML
  • Describing UI artifacts
  • ltDockPanel LastChildFill"True"gt
  • ltStackPanel Orientation"Vertical"
    DockPanel.Dock"Top"gt
  • ltTextBlock Margin"2"gtCountlt/TextBloc
    kgt
  • ltTextBox Margin"5" Text"Binding
    Count" /gt
  • ltTextBlock Margin"2"gtResultslt/TextBl
    ockgt
  • lt/StackPanelgt
  • ltListBox Margin"5" ItemsSource"Binding
    Results" /gt
  • lt/DockPanelgt
  • Describing custom data classes
  • ltmyNumericViewModel Count"5"gt
  • ltmyNumericViewModel.Sequencegt
  • ltmySquareRoots /gt
  • lt/myNumericViewModel.Sequencegt

7
Overview of WPF
  • XAML
  • Many controls accept arbitrary content
  • E.g. a button may contain any combination of
    other controls, such as text, images, and even
    text boxes, etc.
  • Thus no need for special image button or Image
    property on a button class

8
Overview of WPF
  • XAML
  • ImageButtonDemo sample

9
Overview of WPF
  • Data Binding
  • ltTextBlock TextBinding Names.Count /gt
  • ltListBox ItemsSourceBinding Names /gt
  • By default binds to the DataContext object of the
    UI element
  • Can bind to properties of other UI elements,
    static instances, etc.

10
Overview of WPF
  • Dependency Properties
  • CLR properties get, set
  • WPF dependency properties get, set, default
    value, change notification, validation,
    animation, etc.
  • Dependency properties are set via reflection-like
    API
  • WPF DependencyObject class has a map from
    property descriptors to property values
  • Most WPF classes derive (directly or indirectly)
    from DependencyObject

11
Overview of WPF
  • Dependency Properties
  • The Dependency property API is somewhat bulky
  • public class MyStateControl ButtonBase
  • public MyStateControl() base()
  • public Boolean State
  • get return (Boolean)this.GetValue(StatePrope
    rty)
  • set this.SetValue(StateProperty, value)
  • public static readonly DependencyProperty
    StateProperty
  • DependencyProperty.Register(
  • "State",
  • typeof(Boolean),
  • typeof(MyStateControl),
  • new PropertyMetadata(false))

12
Overview of WPF
  • Dependency Properties
  • GetValue(), SetValue() can accept properties
    owned by other classes. These called attached
    properties
  • In XAML attached properties look like so
  • ltDockPanelgt
  • ltTextBlock DockPanel.DockTop /gt
  • lt/DockPanelgt
  • Dock property is owned by the DockPanel class,
    but it is set on a TextBlock instance. This is
    somewhat similar to extension methods in C

13
Overview of WPF
  • Data Change Notification
  • Binding mechanism must know when things change
  • Dependency properties are set via WPF-controlled
    methods GetValue, SetValue

14
Overview of WPF
  • Data Change Notification
  • For regular properties must implement
  • interface INotifyPropertyChanged event
    PropertyChangedclass MyClass
    INotifyPropertyChanged
  • string _data
  • string Data
  • get return _data
  • set if (value _data) return
  • _data value
  • PropertyChanged(Data)

15
Overview of WPF
  • Data Binding
  • Binding source regular property or dependency
    property
  • Binding target dependency property
  • Animation target dependency property

16
Overview of WPF
  • Data Binding
  • NumericFunctions Sample

17
Overview of WPF
  • Data Templates
  • Data templates replace owner draw items in item
    controls like list boxes
  • Rule of thumb avoid assembling text for UI in
    code. Use data templates instead

18
Overview of WPF
  • Data Templates
  • NumericFunctions sample revisited using data
    template

19
Overview of WPF
  • Styles and Control Templates
  • Lookless controls behavior is separated from
    appearance
  • Behavior control class, appearance control
    style
  • Clock control may have Time property, and can
    track current time
  • Styles can define colors, fonts, and even
    completely overhaul the appearance of the control

20
Overview of WPF
  • Styles and Control Templates
  • ClockControl demo

21
Overview of WPF
  • WPF Binaries
  • Main shipped with .NET 3.0 and later
  • WPF toolkit additional controls such as data
    grid, date picker control
  • Prism composite application guidance for WPF

22
Overview of WPF
  • Expression Blend
  • Writing XAML by hand, especially grid layouts,
    may be overwhelming
  • Visual Studio has limited editing capabilities
  • Expression Blend is a separate application for
    editing XAML documents
  • Pros and Cons

23
Overview of WPF
  • MVVM vs MVP

Model
View
Presenter
Model
WPF Binding Mechanism
View
ViewModel
24
Overview of WPF
  • MVVM vs MVP
  • MVVM is a WPF version of MVP
  • View is pure XAML
  • ViewModel has data to display
  • ViewModel may be more detailed/redundant than
    business objects
  • ViewModel does not have a reference to the view

25
Overview of WPF
  • MVVM vs MVP
  • All communication to the view is done via
    bindings
  • Bindings take on most of the work of the
    presenter
  • ViewModel is mostly about presentation data. If
    there is no complex business logic, model is not
    necessary

26
Overview of WPF
  • MVVM and Commands
  • Out of the box WPF does not fully support MVVM
  • Exchanging data is easy, dealing with commands,
    focus, etc. is more difficult. Not having
    reference to the view causes problems
  • Default mechanism of routed commands is not
    compatible with MVVM, since commands are
    delivered to the view

27
Overview of WPF
  • Summary
  • WPF is very flexible, it has almost mathematical
    beauty
  • New approach to UI programming binding, attached
    properties, MVVM
  • A learning curve
  • Fair number of gotchas and bugs
  • Performance is a frequent concern
  • Demand for WPF is on the rise

28
Overview of WPF
  • References
  • Book Programming WPF by Chris Sells
  • WPF toolkit et al. http//wpf.codeplex.com/
  • Prism http//compositewpf.codeplex.com/
  • MVVM
  • http//msdn.microsoft.com/en-us/magazine/dd419663
    .asp
Write a Comment
User Comments (0)
About PowerShow.com