windows presentation foundation · •wpf command model adds: •delegates to the appropriate...

33
WINDOWS PRESENTATION FOUNDATION Philip Japikse (@skimedic) [email protected] www.skimedic.com/blog Microsoft MVP, ASPInsider, MCSD, MCDBA, CSM, CSP

Upload: others

Post on 13-Oct-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

WINDOWS PRESENTATION FOUNDATION

Philip Japikse (@skimedic)

[email protected]

www.skimedic.com/blog

Microsoft MVP, ASPInsider, MCSD, MCDBA, CSM, CSP

Page 2: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

PHIL.ABOUT()

2

•Microsoft MVP, ASPInsider, MCSD, MCDBA, CSM, CSP

• Founder, Agile Conferences, Inc.

• President, Cincinnati .NET User’s Group

• Co-host, Hallway Conversations

•www.hallwayconversations.com

Page 3: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

WHAT IS WPF?

3

• Windows Presentation Foundation

• Next Generation Rich User Application Platform

• Declarative UI (XAML)

• Based on DirectX (not GDI/GDI+)

• Vector Based

• Supports true Hardware Acceleration

• Resolution Independence

• Leaps ahead with binding

• Data and other Elements

Page 4: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

WHAT ELSE IS IN WPF?

4

• Flexible flow layout model

• Styles and Templates

• OOTB document handling features

• True animation – not timer based

• A/V support (through WMP)

• Commands

• Routed Events

Page 5: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

WHAT’S NEW IN .NET 4?

5

• DataGrid, DatePicker, Calendar

• Visual State Manager

• Layout Rounding

• Multi-Touch support

• Custom Dictionaries

• Behaviors*

• Animation Easing

• Binding String Format

Page 6: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

WHAT’S NEW IN .NET 4.5

• Ribbon Control

• Improved Performance with large data

• Binding to Static Properties

• Accessing Collections on non-UI Threads

• Asynchronous Validation

• Delay Updating Data Source

• Retrieving Data Binding Info from Expression

• And more…

• http://tinyurl.com/wpf4-5

Page 7: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

WHAT’S MISSING

7

• WPF – What’s missing

• Visual Inheritance

•MDI – complete lack of support

Page 8: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

AGENDA

8

• Elements, Controls, and More

• Layout/Layout Containers

• Commands

• Custom Dictionaries

• Behaviors

• Binding

Page 9: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

ELEMENTS, CONTROLS, AND MORE

9

Page 10: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

ELEMENTS & CONTROLS

10

• Everything is an Element

• Controls are elements that can:

•Receive Focus

•Accept User Input

• Content Controls

• Hold a single element

•Window (Special)

•Labels, Buttons, CheckBox, RadioButton, ToolTips

•ScrollViewer, Border, Expander

• Text Controls

• TextBox , PasswordBox – Strings Only

• RichTextBox – Sophisticated Content – FlowDocument

Page 11: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

LIST CONTROLS

11

• List Controls (ItemsControl)

• Selectors

•ListBox, ComboBox, TabControl

• Non-Selectors

•Menus, ListView, GridView, TreeView, ToolBar

• Range Based Controls

• ScrollBar, ProgressBar, Slider

Page 12: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

EVENTS

12

• Routed Events replace usual .NET events

• Direct

•Originate in one element and don’t pass on

• Bubbling

•Travel up the element tree

• Tunneling

•Travel down the element tree

• Can add event handlers for child elements

• <Grid Button.Click=“ClickEvent” …

Page 13: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

MENUS

13

• Use “_” instead of “&” for Hot-Key

• Beware for XAML order vs Grid Order

• Similar to WinForms except

•MenuItem is a container control

• Use <Separator> instead of “-”

Page 14: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

LAYOUTS AND LAYOUT CONTAINERS

14

Page 15: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

LAYOUT

15

• “Web”-like layout model with Flexible Flow

•Gone are explicit sizing, absolute positioning, etc

• Containers try to allocate element’s requested space

• Layout Process

•Measure

•Loop through all elements asking for preferred size

• Arrange

•Container places elements in appropriate position

Page 16: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

LAYOUT CONTAINERS

16

• Standard

•Grid

•Most commonly used (default Window Panel)

• StackPanel, WrapPanel, DockPanel

•Used for UI Tweaks

• Canvas

•Absolute (think WinForms) positioning

• InkCanvas - Supports Digital Ink

• Specialized

• UniformGrid, TabPanel, ToolBarPanel, ToolBarOverflowPanel

Page 17: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

ATTACHED PROPERTIES

17

• Properties defined in one element used in another

•Grid.Row/Grid.Column

• Translated into method calls

•Grid.SetRow(control,x)

Page 18: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

Layouts

18

Page 19: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

COMMANDS

19

Page 20: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

COMMANDS

20

• WPF Command Model adds:

• Delegates to the Appropriate Commands

• Keeps state of control tied into state of Command

•Can_Execute

• Consists of:

• Commands – represents an application task

• Command Bindings – links command to code

• Command Sources – trigger the command

• Command Target – element on which the command is being

performed

Page 21: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

Commands

21

Page 22: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

CUSTOM DICTIONARIES

22

Page 23: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

CUSTOM DICTIONARIES

23

• Enable by setting SpellCheck.IsEnabled=“True”

• Text File (<name>.lex) for custom words

• Add as a resource, assign to the CustomDictionaries collection,

copy to output directory

• Four languages supported

• English, Spanish, German, French

Page 24: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

Custom Dictionaries

24

Page 25: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

BEHAVIORS

25

Page 26: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

BEHAVIORS

• Introduced in Expression Blend v3

• Encapsulate functionality into reusable components

• Drag & Drop

• Pan and Zoom

• Input Validation

•Watermark Text

• InvokeCommand

• Additional Behaviors are available from the Expression Gallery

• http://msdn.microsoft.com/en-us/expression/jj873995

Page 27: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

Behaviors

27

Page 28: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

BINDING

28

Page 29: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

ELEMENT BINDING

29

• Allows for powerful UI constructs all defined in XAML

• Can bind elements value directly to another element

No more coding “onChanged” events!

Page 30: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

DATA BINDING

30

• Supports

• IDataErrorInfo

• INotifyPropertyChanged

• INotifyCollectionChanged

• Can bind to *any* Dependency Property

• Choice of

• Datasets

• Data Objects

Page 31: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

Data Binding

31

Page 32: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

WINFORMS/WPF INTEROP

32

• System.Windows.Forms.Integration

•WindowsFormsIntegration.dll

• WindowsFormsHost (WF in WPF)

• Var host = new WindowsFormsHost();

• host.Child = winform;

• UIElement.Children.Add(host);

• ElementHost (WPF in WF)

• ElementHost.EnableModelessKeyboardInterop(window)

Page 33: WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate Commands •Keeps state of control tied into state of Command •Can_Execute •Consists

CONTACT ME

33

[email protected]

•www.skimedic.com/blog

•www.twitter.com/skimedic

•www.hallwayconversations.com

•www.about.me/skimedic