Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

39
Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Transcript of Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Page 2: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

About…• InterKnowlogy (www.InterKnowlogy.com)• Tim Huckaby, CEO ([email protected])

– Custom Application Development / Consulting / Software & Systems Engineering Firm headquartered in Carlsbad, CA

– Design, Architect, Build and Deploy Enterprise Class Applications – Industry Experts:

•Most of the employees are published, MVPs, RD, Speakers, etc.•Microsoft .NET Application development since 2000•Microsoft .NET Rich Client Pioneers / Industry Leaders•Microsoft Touch Application Development Leaders (Surface / Windows 7 / Silverlight 3)•Information Worker Solutions (VSTO & SharePoint)•Integration / Messaging, B2B / B2C, Wireless / Mobility •Leading Edge: Surface, WPF, Silverlight, Win7 touch, SharePoint, VSTO•Cutting Edge Solutions on emerging Microsoft technologies•Largest Client: Microsoft

Page 3: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Demo of the Reference Application

WPF, XAML, and Declarative Programming

Layout and Controls, Events and Commands

Working with Data

Session Objectives And Agenda

Adding Style To Your Application

Page 4: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

WPF Reference Application Demo

Tim HuckabyCEO, InterKnowlogyMicrosoft RD & MVP

DEMO

•Project Structure•XAML and Code Behind•Working with Data•Resources

Page 5: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

WPF and Declarative Programming

• XAML replaces code• Attributes control Layout and Style• Event handlers wired-up in XAML• Declarative Data Binding

Page 6: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Sample XAML

Runs in a WPF Application:

Runs in the Browser::

Page 7: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Layout and Controls

• Layout Basics• Controls

Page 8: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Layout Basics

• Panels• UI Element Positioning

Page 9: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Panels• StackPanel• Arranges child elements into a single line that can be oriented

horizontally or vertically.

• WrapPanel• Positions child elements in sequential position from left to right,

breaking content to the next line at the edge of the containing box.

• DockPanel• An area where you can arrange child elements either horizontally or

vertically, relative to each other.

• Grid• A flexible grid area that consists of columns and rows.

• Canvas• An area within which you can explicitly position child elements by

using coordinates that are relative to the Canvas area.

Page 10: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Container Controls

• Canvas• DockPanel• DocumentViewer• Frame• Grid• StackPanel• Tab

Page 11: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Positioning

• Horizontal and Vertical Alignment• Margin• Padding

Margin

Text Block Text Block

Padding

Page 12: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Controls

• Standard Common Controls• Menu and Toolbar Controls• Container Controls• New Controls

Page 13: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Standard Common Controls

• TextBox• Button• CheckBox / ComboBox• Image• Label• ListBox• Password

Page 14: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Menu and Toolbar Controls

• Menu• Context Menu• StatusBar• ToolBar• ToolBarTray

Page 15: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Controls unique to WPF

• TextBlock• Expander• InkCanvas• InkPresenter• DocumentViewer• UniformGrid

Page 16: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Screen Layout Demo

Tim HuckabyCEO, InterKnowlogyMicrosoft RD & MVP

DEMO

Page 17: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Events and Commands

• Standard .NET Events• Routed Events• Commands

Page 18: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Routed Events

• Bubbling– Starts at the current element and bubbles up to the

current element’s parent and that elements parent and so on [MouseLeftButtonDown]

• Tunneling– Works opposite of bubbling and starts at the root element

and works down to the originating element [PreviewMouseLeftButtonDown]

• Direct– Works like standard .NET event handling with only direct

handlers being notified of events [Click]

Page 19: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Commands

• Logical action that can be invoke in several ways

• Based on the RoutedCommand Class• Uses both event tunneling

[PreviewExecuteEvent] and event bubbling [ExecuteEvent]

Page 20: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Events and Commands Demo

Tim HuckabyCEO, InterKnowlogyMicrosoft RD & MVP

DEMO

Page 21: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Working with Data

• Overview• Simple Data Binding• Complex Data Binding

Page 22: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Data Binding

• Simple Field level Data Binding• Complex Data Binding to multiple controls at a

time (Master/Detail/Detail)• Client-Side Sorting and Filtering• Support for binding to Objects, XML and

Relational data sources

Page 23: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Simple Data Binding

• Simple Data Binding using Business Objects• Support for two-way synchronization in simple

objects via the INotifyPropertyChanged interface

• Implicit and Declarative binding via the DataContext

Page 24: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Complex Data Binding

• Binding to Lists• Supports two-way data binding to list if list

inherits from ObservableCollection<T>• Data Templates• Sorting• Filtering• Master/Detail/Detail

Page 25: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Working with Data Demo

Tim HuckabyCEO, InterKnowlogyMicrosoft RD & MVP

DEMO

Page 26: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Adding Style to Your Application

• Overview• Resources• Triggers

Page 27: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

XAML Styles

• What are styles?• Problems they address in WinForms 2.0– Styling controls one at a time– Unnecessary Custom Control Creation

• Similarities to Cascading Style Sheets– Inline declaration– Page level declaration– Separate file declaration

Page 28: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Style Examples

Page 29: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Resources

• Static Resources– Loaded when Window or Page Loads– Leads to slower page loading– Changes to underlining values are not propagated

• Dynamic Resources– More overhead to allow for constant updates– Can only be used to set dependency properties– Can potentially improve Page and Window load

time

Page 30: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Resource Dictionary

• Contains hash table of resources• Great way to organize resources• Resource.MergedDictionaries combines many

different file based resources

Page 31: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Triggers

• Setters that are set based on one or more conditions

• Three Types of Triggers– Property – Invoked when the value of a

dependency property changes– Data – Invoked when the value of a plain .NET

property changes– Event – Invoked when a routed event changes

Page 32: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Adding Style to Your Application

Tim HuckabyCEO, InterKnowlogyMicrosoft RD & MVP

DEMO

Page 33: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Summary

• Layout in WPF is flexible• WPF has a rich set of controls• Data Binding is rich & supports many data types• Styles bring life to your applications• The learning curve can be steep, but is worth it.• Download all my resources and dedicate some time to

learn.

Page 34: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Where to go next:http://WindowsClient.InterKnowlogy.com

• Windows Client Guidance Microsoft Platform Solution Architecture for the Application Developer

by Tim Huckaby

• The “Anchor Document” to a ton of Rich Client Guidance

Page 35: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

WPF: Where to go Next Free Resources

• WindowsClient.net - this is the official Microsoft community portal for WPF development, and is chock full of great resources

• Windows Client Development Samples, Guidance, FAQs and Blogs - Contains an aggregation of a ton of great stuff on the Windows Client Development platform.

• Learn WPF page - this page links to podcasts, labs, and the very popular "how do I?" videos

• MIX University's WPF Boot Camp - this is a full 3-day video training course on WPF, in which expert instructors guide you from the surface into the depths of the technology stack

Page 37: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Where to go…soon…• Windows Presentation

Foundation A Scenario-Based Approach

by Billy Hollis

• “Early April…I hope…”B. Hollis, 12/7/07

• “October…”B. Hollis, 6/3/08

• “It’s not going to be done in April.”

B. Hollis, 2/24/09• “I took a .NET 4.0 dependency. Projected date now

Jan 2010, because it can’t come out until VS2010 is released.”

• B. Hollis, 4/29/09

Page 38: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Where to go next :

The InterKnowlogy WPF Reference Application

Page 39: Tim Huckaby CEO, InterKnowlogy Microsoft RD & MVP Jump into WPF!

Tim Huckaby, InterKnowlogy• More info on InterKnowlogy:– www.InterKnowlogy.com

• Contact me: Tim Huckaby

– E-mail: [email protected]– Phone: 760-444-8640– Blog: http://team.interknowlogy.com/blogs/timhuckaby

• About Tim Huckaby…– CEO, InterKnowlogy– Microsoft® Regional Director – Southern California– Microsoft® .NET Partner Advisory Council Founder / Member– Microsoft® MVP - .NET – Microsoft® Surface Partner Advisory Council– INETA Speaker – International .NET Users Group Association– Windows and .NET Magazine Advisory Board Member– .NET Developers Journal Magazine Advisory Board Member– Author / Speaker