WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate...
Transcript of WINDOWS PRESENTATION FOUNDATION · •WPF Command Model adds: •Delegates to the Appropriate...
WINDOWS PRESENTATION FOUNDATION
Philip Japikse (@skimedic)
www.skimedic.com/blog
Microsoft MVP, ASPInsider, MCSD, MCDBA, CSM, CSP
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
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
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
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
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
WHAT’S MISSING
7
• WPF – What’s missing
• Visual Inheritance
•MDI – complete lack of support
AGENDA
8
• Elements, Controls, and More
• Layout/Layout Containers
• Commands
• Custom Dictionaries
• Behaviors
• Binding
ELEMENTS, CONTROLS, AND MORE
9
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
LIST CONTROLS
11
• List Controls (ItemsControl)
• Selectors
•ListBox, ComboBox, TabControl
• Non-Selectors
•Menus, ListView, GridView, TreeView, ToolBar
• Range Based Controls
• ScrollBar, ProgressBar, Slider
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” …
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 “-”
LAYOUTS AND LAYOUT CONTAINERS
14
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
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
ATTACHED PROPERTIES
17
• Properties defined in one element used in another
•Grid.Row/Grid.Column
• Translated into method calls
•Grid.SetRow(control,x)
Layouts
18
COMMANDS
19
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
Commands
21
CUSTOM DICTIONARIES
22
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
Custom Dictionaries
24
BEHAVIORS
25
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
Behaviors
27
BINDING
28
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!
DATA BINDING
30
• Supports
• IDataErrorInfo
• INotifyPropertyChanged
• INotifyCollectionChanged
• Can bind to *any* Dependency Property
• Choice of
• Datasets
• Data Objects
Data Binding
31
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)
CONTACT ME
33
•www.skimedic.com/blog
•www.twitter.com/skimedic
•www.hallwayconversations.com
•www.about.me/skimedic