Presentation is loading. Please wait.

Presentation is loading. Please wait.

Important New Concepts In WPF

Similar presentations


Presentation on theme: "Important New Concepts In WPF"— Presentation transcript:

1 Important New Concepts In WPF
Orlando Robertson Brown Bag Seminar Windows Presentation Foundation Unleashed

2 Introduction This chapter introduces concepts beyond .NET programming
New Concepts Logical Trees Visual Trees Extended Concepts Dependency Properties Routed Events Commands Review UI applications needed for programming

3 Logical & Visual Trees Logical Trees are objects to create UIs in WPF
Important because every aspect in WPF is associated to Logical Trees Visual Trees are considered an expanded logical tree exposing visual components Visual Trees expose elements derived from System.Windows.Media.Visual &Visual3D

4 Logical & Visual Trees

5 Logical & Visual Trees

6 Logical & Visual Trees Visual Trees & Logical Trees are needed for applications separating look and logic Logical Trees can be traversed using class System.Windows.LogicalTreeHelper Visual Trees can be traversed using class System.Windows.VisualTreeHelper

7 Dependency Properties
Dependency Property is a new WPF property type used to enable styling, automatic data binding, animation Dependency Properties provide change notifications from declarative markup Also property value inheritance & multiple provider support Styling and Animation are done with dependency properties

8 A Dependency Property Implementation
Dependency Properties are .NET properties connected to extra WPF infrastructure Represented by System.Windows.DependencyProperty Created by calling DependencyProperty.Register Options for passing metadata, callbacks, coercing values, validating values .NET property wrappers are bypassed at run-time when setting Dependency Properties in XAML

9 Change Notification Change Notifications allows WPF to automatically trigger actions when dependency properties change Property Trigger, Data Trigger, Event Trigger Property Trigger allows custom changes when property values change without procedural code Data Trigger works for all .NET properties, not just dependency properties Event Trigger declaratively specifies actions for raised events Used for animation and sound applications

10 Property Value Inheritance
Property Value Inheritance refers to flow of property values down the element tree Child elements inherit properties of the parent element unless overridden Elements deriving from Freezable may inherit values from the parent element

11 Support for Multiple Providers
WPF executes a 5 step process to calculate the final value of dependency properties using change notifications Step 1 Determine Base Value Applies a precedence order for property providers Step 2 Evaluate Evaluate expressions from step 1 Step 3 Apply Animations Apply animation values to current properties

12 Support for Multiple Providers
Step 4 Coerce Passes the resulting property values to a CoerceValueCallback delegate Step 5 Validate Passes the coerced property values to a ValidateValueCallback delegate

13 Attached Properties Attached Properties are special dependency properties assigned to arbitrary objects Objects that don’t have a dependency property of it’s own can be attached and used for property value inheritance Ex. Assigning a FontSize to a StackPanel

14 Routed Events Routed Events traverse thru visual and logical trees without the need for custom code Provides the service of encapsulation of application from visual trees Allows for embedded complex content and visual trees

15 A Routed Event Implementation
Routed Events are static public fields Routed Events are represented by RoutedEvents Created by calling EventManger.RegisterRoutedEvent

16 Routing Strategies & Event Handlers
RoutingStrategy enumeration: Tunneling, Bubbling, Direct Tunneling raises the routed event at the root then to each element toward the source element Bubbling raises the routed event at the source element then to each element toward the root Direct raises the routed event at the source element only

17 Routing Strategies & Event Handlers
Routed Event handlers are similar to .NET event handlers 1st Parameter is System.Object sender 2nd Parameter is RoutedEventArgs e RoutedEventArgs derived from EventArgs

18 Routed Events in Action
UIElement class defines routed events for keyboard, mouse, stylus input Many of the bubbling events are paired with tunneling events Naming convention of tunneling events are prefixed with Preview Tunneling Event: PreviewMouseMove Bubbling Event: MouseMove Event pairing provides the option of canceling or modifying a bubbling event

19 Attached Events Attached Events provide tunneling and bubbling of routed events to elements that don’t define the event Similar to attached properties Routed events can be used as attached events

20 Commands Commands represent independent actions from the UI
Multiple commands can be exposed with the use of events WPF reduces the amount of code needed to support commands WPF provides flexibility to change UIs supporting commands without breaking back-end logic

21 Built-In Commands WPF defines many commands ready for use
ApplicationCommands: Cut, Paste ComponentCommands: MoveUp, MoveDown MediaCommands: ChannelUp, ChannelDown NavigationCommands: Search, Refresh EditingCommands: AlignLeft, AlignCenter These commands are instances of RoutedUICommand Implements ICommand & Supports Bubbling

22 Executing Commands w/ Input Gestures
Input Gestures can be bound to commands by adding a KeyBinding or MouseBinding to the elements InputBindings collection Ex Help command provides auto binding to keyboard shortcuts Default: F1 Key Input Gestures can assign F2 key to execute Help command

23 Controls w/ Built-In Command Bindings
Some controls in WPF have their own command bindings Ex TextBox control bound to Cut, Paste Built-In Commands can be bound by WPF controls Button bound to a TextBox Built-In command WPF’s built-in commands becomes important Buttons and TextBoxes can gain rich interaction

24 A Tour of the Class Hierarchy

25 Conclusion We learned the major WPF applications for the .NET Framework Reviewed types of properties, types of events, trees, declarative code, procedural code We now have an understanding of WPF controls and developing WPF UIs.

26 References “Windows Presentation Foundation Unleashed”, Adam Nathan with Daniel Lehenbauer Software Requirements Windows that support .NET 3.0: XP SP2, Vista .NET Framework 3.0 Software Recommended Windows SDK ( Visual Studio 2005 or later


Download ppt "Important New Concepts In WPF"

Similar presentations


Ads by Google