overview of wpf
Download
Skip this Video
Download Presentation
Overview of WPF

Loading in 2 Seconds...

play fullscreen
1 / 28

Overview of WPF - PowerPoint PPT Presentation


  • 124 Views
  • Uploaded on

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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
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

E-mail:

[email protected]

[email protected]

http://www.ikriv.com/demo/wpf/

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

WPF =

XAML

+ Data Binding

+ Styles

overview of wpf4
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
overview of wpf5
Overview of WPF

XAML

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>

</StackPanel>

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

</DockPanel>

Describing custom data classes:

<my:NumericViewModel Count="5">

<my:NumericViewModel.Sequence>

<my:SquareRoots />

</my:NumericViewModel.Sequence>

</my:NumericViewModel>

overview of wpf6
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
overview of wpf7
Overview of WPF

XAML

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

DependencyProperty.Register(

"State",

typeof(Boolean),

typeof(MyStateControl),

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:

<DockPanel>

<TextBlock DockPanel.Dock=“Top” />

</DockPanel>

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

PropertyChanged(…”Data”…);

}

}}

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

MVVM vs MVP

Model

View

Presenter

Model

WPF

Binding

Mechanism

View

ViewModel

overview of wpf23
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
overview of wpf24
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
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

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
overview of wpf27
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

ad