Overview of wpf
1 / 28

Overview of WPF - PowerPoint PPT Presentation

  • Uploaded on

Overview of WPF. Ivan Krivyakov Senior Managing Consultant SunGard Consulting Services E-mail: Ivan.Krivyakov@SunGard.com ivan@ikriv.com http://www.ikriv.com/demo/wpf/. Overview of WPF. What Is This Presentation About WPF for an experienced developer What makes WPF different?

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Overview of WPF' - lyle

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Overview of wpf
Overview of WPF

Ivan Krivyakov

Senior Managing Consultant

SunGard Consulting Services





Overview of wpf1
Overview of WPF

What Is This Presentation About

  • WPF for an experienced developer

  • What makes WPF different?

  • Things to explore

  • Definitely not a tutorial

Overview of wpf2
Overview of WPF

Why Is WPF Important?

  • It’s 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

Overview of wpf3
Overview of WPF

A Contrived Mixture Formula



+ Data Binding

+ Styles

Overview of wpf4
Overview of WPF


  • 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

Overview of wpf5
Overview of WPF


Describing UI artifacts:

<DockPanel LastChildFill="True">

<StackPanel Orientation="Vertical" DockPanel.Dock="Top">

<TextBlock Margin="2">Count:</TextBlock>

<TextBox Margin="5" Text="{Binding Count}" />

<TextBlock Margin="2">Results:</TextBlock>


<ListBox Margin="5" ItemsSource="{Binding Results}" />


Describing custom data classes:

<my:NumericViewModel Count="5">


<my:SquareRoots />



Overview of wpf6
Overview of WPF


  • 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

Overview of wpf7
Overview of WPF


  • ImageButtonDemo sample

Overview of wpf8
Overview of WPF

Data Binding

<TextBlock Text=“{Binding Names.Count}” />

<ListBox ItemsSource=“{Binding Names}” />

  • By default binds to the DataContext object of the UI element

  • Can bind to properties of other UI elements, static instances, etc.

Overview of wpf9
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

Overview of wpf10
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(StateProperty); }

set { this.SetValue(StateProperty, value); }


public static readonly DependencyProperty StateProperty =





new PropertyMetadata(false));


Overview of wpf11
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:


    <TextBlock DockPanel.Dock=“Top” />


  • “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#

Overview of wpf12
Overview of WPF

Data Change Notification

  • Binding mechanism must know when things change

  • Dependency properties are set via WPF-controlled methods GetValue, SetValue

Overview of wpf13
Overview of WPF

Data Change Notification

For regular properties must implement

interface INotifyPropertyChanged{ event … PropertyChanged;}class MyClass : INotifyPropertyChanged{

string _data;

string Data {

get { return _data; }

set { if (value == _data) return;

_data = value;




Overview of wpf14
Overview of WPF

Data Binding

  • Binding source: regular property or dependency property

  • Binding target: dependency property

  • Animation target: dependency property

Overview of wpf15
Overview of WPF

Data Binding

  • NumericFunctions Sample

Overview of wpf16
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

Overview of wpf17
Overview of WPF

Data Templates

  • NumericFunctions sample revisited using data template

Overview of wpf18
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

Overview of wpf19
Overview of WPF

Styles and Control Templates

  • ClockControl demo

Overview of wpf20
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

Overview of wpf21
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

Overview of wpf22
Overview of WPF











Overview of wpf23
Overview of WPF


  • 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

Overview of wpf24
Overview of WPF


  • 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

Overview of wpf25
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

Overview of wpf26
Overview of WPF


  • 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

Overview of wpf27
Overview of WPF


  • Book: “Programming WPF” by Chris Sells

  • WPF toolkit et al.: http://wpf.codeplex.com/

  • Prism:http://compositewpf.codeplex.com/

  • MVVM: