WPF Windows Presentation Foundation A detailed overview Version1.2


Published on

Agenda: WPF Windows Presentation Foundation
To: Development Team
By: Shahzad Sarwar
Date:Friday, November 20, 2009

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

WPF Windows Presentation Foundation A detailed overview Version1.2

  1. 1. WPF, Windows Presentation Foundation A platform for building rich user experiences on Windows An Architect overview By Shahzad sarwar
  2. 2. Presentation Scope <ul><li>What's covered: </li></ul><ul><ul><li>XMAL </li></ul></ul><ul><ul><li>Basic Elements of WPF </li></ul></ul><ul><ul><li>Architecture </li></ul></ul><ul><ul><li>Property System / Dependency Property </li></ul></ul><ul><ul><li>Routed Events </li></ul></ul><ul><ul><li>Binding System </li></ul></ul><ul><ul><li>Styling / Templating </li></ul></ul><ul><li>What’s Not covered: </li></ul><ul><ul><li>Controls Library </li></ul></ul><ul><ul><li>Graphics / Multi Media </li></ul></ul><ul><ul><li>Documents </li></ul></ul>
  3. 3. What is WPF? <ul><li>Next-generation presentation system for building Windows client applications with visually stunning user experiences. </li></ul><ul><li>Resolution-independent </li></ul><ul><li>Vector-based rendering engine (advantage of modern graphics hardware) </li></ul><ul><li>Coverage: </li></ul><ul><li>Extensible Application Markup Language (XAML), controls, data binding, layout, 2-D and 3-D graphics, animation, styles, templates, documents, media, text, and typography. </li></ul><ul><li>Types Of Applications: </li></ul><ul><li>1. Standalone Applications: </li></ul><ul><ul><li>Window class to create windows and dialog boxes </li></ul></ul><ul><ul><li>Accessed from menu bars and tool bars. </li></ul></ul><ul><li>2. Browser-Hosted Applications: </li></ul><ul><li>(XAML browser applications (XBAPs)) </li></ul><ul><ul><li>Create pages (Page) and page functions (PageFunction(T))  </li></ul></ul><ul><ul><li>Navigate between using hyperlinks (Hyperlink classes). </li></ul></ul>
  4. 4. Tech Analysis Reference: http:// windowsclient.net/wpf/white-papers/when-to-adopt-wpf.aspx X X         3D Graphics X     X     2D Graphics X   X       Video / Audio X     X     Images X       X   Complex text X     X   X Forms, Controls WPF Direct3D Windows Media Player WinForms + GDI PDF WinForms
  5. 5. The Application Class <ul><li>Additional application-scoped services, including </li></ul><ul><li>Creating and managing common application infrastructure. </li></ul><ul><li>Tracking and interacting with application lifetime. </li></ul><ul><ul><li>Startup </li></ul></ul><ul><ul><li>Activated </li></ul></ul><ul><ul><li>Deactivated </li></ul></ul><ul><ul><li>ShutdownMode </li></ul></ul><ul><ul><li>(OnLastWindowClose,OnMainWindowClose, </li></ul></ul><ul><ul><li>OnExplicitShutdown) </li></ul></ul><ul><ul><li>SessionEnding </li></ul></ul><ul><ul><li>(Logging off,Shutting down,Restarting,Hibernating) </li></ul></ul><ul><ul><li>Exit </li></ul></ul><ul><li>Retrieving and processing command-line parameters. </li></ul><ul><li>Example </li></ul><ul><li>Sharing application-scope properties and resources. </li></ul><ul><li>Examples in Code </li></ul><ul><li>Detecting and responding to unhandled exceptions. </li></ul><ul><li>Example in Code </li></ul>
  6. 6. The Application Class <ul><li>Returning exit codes. </li></ul><ul><li>Example in Code </li></ul><ul><li>Managing windows in standalone applications </li></ul><ul><li>Tracking and managing navigation </li></ul><ul><li>using System.Windows.Navigation; </li></ul><ul><ul><li>1. <Hyperlink Control </li></ul></ul><ul><li><Hyperlink NavigateUri=&quot;UriOfPageToNavigateTo.xaml&quot;> </li></ul><ul><li>Navigate to Another Page </li></ul><ul><li></Hyperlink> </li></ul><ul><li>2. Via NavigationService </li></ul><ul><li>// Instantiate the page to navigate to </li></ul><ul><li>PageWithNonDefaultConstructor page = new PageWithNonDefaultConstructor(&quot;Hello!&quot;); </li></ul><ul><li>// Navigate to the page, using the NavigationService </li></ul><ul><li>this .NavigationService.Navigate(page); </li></ul>
  7. 7. The Application Class <ul><li>3.Programmatic Navigation with a Pack URI </li></ul><ul><li>// Create a pack URI </li></ul><ul><li>Uri uri = new Uri(&quot;AnotherPage.xaml&quot;, UriKind.Relative); </li></ul><ul><li>// Get the navigation service that was used to </li></ul><ul><li>// navigate to this page, and navigate to </li></ul><ul><li>// AnotherPage.xaml </li></ul><ul><li>this .NavigationService.Navigate(uri); </li></ul><ul><li>Configuring the Host Window's Title, Width, and Height </li></ul><ul><li>Fragment Navigation </li></ul><ul><li>Navigation to a content fragment </li></ul><ul><li>PageURI # ElementName </li></ul>
  8. 8. Navigation Lifetime <ul><li>Navigating . Occurs when a new navigation is requested. Can be used to cancel the navigation. </li></ul><ul><li>NavigationProgress . Occurs periodically during a download to provide navigation progress information. </li></ul><ul><li>Navigated . Occurs when the page has been located and downloaded. </li></ul><ul><li>NavigationStopped . Occurs when the navigation is stopped (by calling StopLoading), or when a new navigation is requested while a current navigation is in progress. </li></ul><ul><li>NavigationFailed . Occurs when an error is raised while navigating to the requested content. </li></ul><ul><li>LoadCompleted . Occurs when content that was navigated to is loaded and parsed, and has begun rendering. </li></ul><ul><li>FragmentNavigation Occurs when navigation to a content fragment begins, which happens: </li></ul><ul><ul><li>Immediately, if the desired fragment is in the current content. </li></ul></ul><ul><ul><li>After the source content has been loaded, if the desired fragment is in different content. </li></ul></ul>
  9. 9. Navigation Lifetime
  10. 10. Navigation Lifetime <ul><li>Journal / journal entry( JournalEntry class ) </li></ul><ul><li>The back stack, the forward stack </li></ul><ul><li>1. Declarative mechanisms provided by WPF </li></ul><ul><li><Hyperlink Members of the NavigationService classCommand=&quot;NavigationCommands.BrowseBack&quot;>Back</Hyperlink> </li></ul><ul><li>2. Programmatic mechanisms provided by WPF </li></ul><ul><li>GoBack </li></ul><ul><li>GoForward </li></ul><ul><li>CanGoBack </li></ul><ul><li>CanGoForward </li></ul><ul><li>Retaining Content State with Navigation History </li></ul><ul><ul><li>New Page, so data is destroyed, But there is a mechanism to restore state via Journal like navigation history. </li></ul></ul><ul><ul><li>Custom implementation is also provided </li></ul></ul><ul><ul><li>System.Windows.Navigation.CustomContentState </li></ul></ul>
  11. 11. Navigation Lifetime <ul><li>Structured Navigation Overview </li></ul><ul><ul><ul><li>Structured Navigation with PageFunction </li></ul></ul></ul><ul><ul><ul><li>Other Types of Structured Navigation </li></ul></ul></ul><ul><li>NavigationWindow Class </li></ul><ul><ul><ul><li>browser-style navigation into your standalone applications </li></ul></ul></ul><ul><ul><ul><li>Navigation Hosts </li></ul></ul></ul><ul><li>Configuring the Application Definition for MSBuild </li></ul><ul><ul><ul><li>In MSBuild project </li></ul></ul></ul><ul><ul><ul><li><ApplicationDefinition Include=&quot;App.xaml&quot; /> </li></ul></ul></ul><ul><ul><ul><li>Getting the Current Application </li></ul></ul></ul><ul><ul><ul><li>// Get strongly-typed current application </li></ul></ul></ul><ul><ul><ul><li>App app = (App)App.Current; </li></ul></ul></ul><ul><li>Two way to Start Window or Page </li></ul><ul><li>1. ByCode </li></ul><ul><ul><ul><li>void App_Startup(object sender, StartupEventArgs e) </li></ul></ul></ul><ul><ul><ul><li>{ </li></ul></ul></ul><ul><ul><ul><li>((NavigationWindow)this.MainWindow).Navigate(new Uri(&quot;HomePage.xaml&quot;, UriKind.Relative)); </li></ul></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul><ul><li>2. StartupUri=&quot;MainWindow.xaml&quot; </li></ul>
  12. 12. WPF Architecture
  13. 13. WPF Architecture <ul><li>More declarative, &quot;property centric&quot; model of programming </li></ul><ul><li>System.Threading.DispatcherObject </li></ul><ul><ul><li>Support for concurrency and threading. </li></ul></ul><ul><ul><li>messaging system implemented by the dispatcher. </li></ul></ul><ul><ul><li>Create a CLR object that has STA behavior. </li></ul></ul><ul><li>Thread affinity: </li></ul><ul><ul><li>A component uses the identity of the executing thread to store some type of state. </li></ul></ul><ul><ul><li>OLE 2.0, the clipboard, and Internet Explorer all require single thread affinity (STA) execution. </li></ul></ul><ul><li>The dispatcher: </li></ul><ul><ul><li>Basic message dispatching system, with multiple prioritized queues </li></ul></ul><ul><ul><li>Examples of messages include: </li></ul></ul><ul><ul><ul><li>Raw input notifications (mouse moved) </li></ul></ul></ul><ul><ul><ul><li>Framework functions (layout) </li></ul></ul></ul><ul><ul><ul><li>User commands (execute this method). </li></ul></ul></ul>
  14. 14. WPF Architecture <ul><li>System.Windows.DependencyObject </li></ul><ul><li>Dependency Properties: </li></ul><ul><li>To compute the value of a property based on the value of other inputs </li></ul><ul><ul><li>System properties such as themes and user preference </li></ul></ul><ul><ul><li>Just-in-time property determination mechanisms such as data binding and animations/storyboards </li></ul></ul><ul><ul><li>Multiple-use templates such as resources and styles </li></ul></ul><ul><ul><li>Values known through parent-child relationships with other elements in the element tree </li></ul></ul><ul><ul><li>Also For: </li></ul></ul><ul><ul><li>Self-contained validation </li></ul></ul><ul><ul><li>Default values </li></ul></ul><ul><ul><li>Callbacks that monitor changes to other properties </li></ul></ul><ul><ul><li>A system that can coerce property values based on potentially runtime information. </li></ul></ul>
  15. 15. WPF Architecture <ul><li>System.Windows.Media.Visual </li></ul><ul><ul><li>Building a tree of visual objects </li></ul></ul><ul><ul><li>Drawing instructions and metadata about how to render those instructions </li></ul></ul><ul><ul><li>(clipping, transformation, etc.). </li></ul></ul><ul><ul><li>Point of connection between these two subsystems, the managed API and the unmanaged milcore. </li></ul></ul>
  16. 16. WPF Architecture <ul><li>Composition: </li></ul><ul><li>In User32 and GDI: </li></ul><ul><ul><li>(Immediate mode clipping system) </li></ul></ul><ul><ul><li>a clipping bounds outside of which the component isn’t allowed to touch the pixels, and then the component is asked to paint pixels in that box. </li></ul></ul><ul><ul><li>Good for memory constrained environment. </li></ul></ul><ul><li>In WPF: </li></ul><ul><ul><li>&quot;Painter's algorithm&quot; painting model. </li></ul></ul><ul><ul><li>To render from the back to the front of the display. </li></ul></ul><ul><ul><li>Each component to paint over the previous component's display. </li></ul></ul><ul><ul><li>Complex, partially transparent shapes. </li></ul></ul><ul><ul><li>Better for new type of graphics object. </li></ul></ul>
  17. 17. WPF Architecture <ul><li>System.Windows.UIElement </li></ul><ul><li>Core subsystems including Layout, Input, and Events. </li></ul><ul><li>Layout: </li></ul><ul><li>1. A fixed set of layout models (HTML supports three models for layout; flow, absolute, and tables) </li></ul><ul><li>2. No model for layout (User32 really only supports absolute positioning) </li></ul><ul><li>A flexible, extensible layout model, which could be driven by property values rather than imperative logic. </li></ul><ul><li>A two phase model with Measure and Arrange passes. </li></ul><ul><ul><li>Measure Phase: To determine how much size it would like to take. </li></ul></ul><ul><ul><ul><li>A parent element will ask a child to measure several times to determine its optimal position and size. </li></ul></ul></ul><ul><ul><ul><li>Rule: Size to content. </li></ul></ul></ul><ul><ul><li>Arrange phase: To allows a parent to position and determine the final size of each child. </li></ul></ul><ul><li>Input: </li></ul><ul><ul><li>On a kernel mode device driver. </li></ul></ul><ul><ul><li>Gets routed to the correct process and thread by involving the Windows kernel and User32. </li></ul></ul><ul><ul><li>Routed to WPF. </li></ul></ul><ul><ul><li>WPF raw input message and sent to the dispatcher. </li></ul></ul><ul><ul><li>Raw input events to be converted to multiple actual events. </li></ul></ul>
  18. 18. WPF Architecture <ul><li>Routing through the element tree. </li></ul><ul><ul><li>Events are said to &quot;bubble&quot; if they traverse from a target up the tree to the root. </li></ul></ul><ul><ul><li>Events are said to &quot;tunnel&quot; if that start at the root and traverse down to a target. </li></ul></ul><ul><li>In the dispatcher for your application you would call TranslateAccelerator which would sniff the input messages in User32 and determine if any matched a registered accelerator. </li></ul><ul><li>CommandBindings. </li></ul><ul><ul><li>To define functionality in terms of a command end point – something that implements ICommand. </li></ul></ul><ul><ul><li>Enable an element to define a mapping between an input gesture (Ctrl+N) and a command (New). </li></ul></ul>
  19. 19. WPF Architecture <ul><li>System.Windows.FrameworkElement </li></ul><ul><ul><li>A set of policies and customizations on the subsystems introduced in lower layers of WPF. </li></ul></ul><ul><ul><li>A set of new subsystems </li></ul></ul><ul><li>Policies: </li></ul><ul><ul><li>Application layout </li></ul></ul><ul><ul><li>Direct access to animation through the BeginStoryboard method </li></ul></ul><ul><ul><li>The data binding subsystem: one or more properties from a given element to be bound to a piece of data </li></ul></ul><ul><ul><li>Styling Subsystem: Bind a set of properties from a shared definition to one or more instances of an element. </li></ul></ul><ul><li>System.Windows.Controls.Control </li></ul><ul><ul><li>Templating allows a control to describe it’s rendering in a parameterized, declarative manner. </li></ul></ul><ul><ul><li>The implementation of a control provides a data model and interaction model </li></ul></ul><ul><ul><li>This split between the data model (properties), interaction model (commands and events), and display model (templates) enables complete customization of a control’s look and behavior. </li></ul></ul>
  20. 20. WPF property system <ul><li>A set of services that can be used to extend the functionality of a common language runtime (CLR) property. </li></ul><ul><li>Dependency property: </li></ul><ul><li>A property that is backed by the WPF property system. </li></ul><ul><li>What For? </li></ul><ul><li>1. A way to compute the value of a property based on the value of other inputs </li></ul><ul><ul><li>System properties such as themes and user preference </li></ul></ul><ul><ul><li>Just-in-time property determination mechanisms such as data binding and animations/storyboards Multiple-use templates such as resources and styles </li></ul></ul><ul><ul><li>Values known through parent-child relationships with other elements in the element tree. </li></ul></ul><ul><li>2. To provide self-contained validation, default values, callbacks that monitor changes to other properties </li></ul><ul><li>3. A system that can coerce property values based on potentially runtime information. </li></ul><ul><li>4. Derived classes can also change some specific characteristics of an existing property by overriding dependency property metadata, rather than overriding the actual implementation of existing properties or creating new properties. </li></ul>
  21. 21. Common Terms <ul><li>DependencyProperty: Extend property functionality by providing a type that backs a property </li></ul><ul><li>DependencyObject: The base class that can register and own a dependency property </li></ul><ul><li>Dependency property identifier: A DependencyProperty instance, which is obtained as a return value when registering a dependency property, and then stored as a member of a class. </li></ul><ul><li>CLR &quot;wrapper&quot;: The actual get and set implementations for the property </li></ul><ul><ul><ul><li>public static readonly DependencyProperty IsSpinningProperty = </li></ul></ul></ul><ul><ul><ul><li>DependencyProperty.Register( </li></ul></ul></ul><ul><ul><ul><li>... </li></ul></ul></ul><ul><ul><ul><li>); </li></ul></ul></ul><ul><ul><ul><li>public bool IsSpinning </li></ul></ul></ul><ul><ul><ul><li>{ </li></ul></ul></ul><ul><ul><ul><li>get { return (bool)GetValue(IsSpinningProperty); } </li></ul></ul></ul><ul><ul><ul><li>set { SetValue(IsSpinningProperty, value); } </li></ul></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul>
  22. 22. Setting Property Values <ul><li>1. XAML attribute </li></ul><ul><li><Button Background=&quot;Red&quot; Content=&quot;Button!&quot;/> </li></ul><ul><li>2. Property element syntax. </li></ul><ul><ul><li><Button Content=&quot;Button!&quot;> </li></ul></ul><ul><ul><li><Button.Background> </li></ul></ul><ul><ul><li><ImageBrush ImageSource=&quot;wavy.jpg&quot;/> </li></ul></ul><ul><ul><li></Button.Background> </li></ul></ul><ul><ul><li></Button> </li></ul></ul><ul><li>3. Setting Properties in Code </li></ul><ul><ul><li>Button myButton = new Button(); </li></ul></ul><ul><ul><li>myButton.Width = 200.0; </li></ul></ul>
  23. 23. Routed events <ul><li>A type of event that can invoke handlers on multiple listeners in an element tree, rather than just on the object that raised the event. </li></ul><ul><li>CLR event that is backed by an instance of the RoutedEvent class and is processed by the Windows Presentation Foundation (WPF) event system. </li></ul><ul><li>Routed events are events who navigate up or down the visual tree acording to their RoutingStrategy. </li></ul><ul><li>Top-level Scenarios for Routed Events </li></ul><ul><li>Control composition and encapsulation: </li></ul><ul><ul><li>Eg: Rich content model. Like an image inside of a Button. </li></ul></ul><ul><li>Singular handler attachment points: </li></ul><ul><ul><li>To attach the same handler multiple times to process events that could be raised from multiple elements. </li></ul></ul><ul><ul><li>Example Code </li></ul></ul><ul><li>Class handling: Permit a static handler that is defined by the class. </li></ul><ul><ul><li>(the opportunity to handle an event before any attached instance handlers can. </li></ul></ul><ul><li>Referencing an event without reflection: </li></ul><ul><ul><li>Creates a RoutedEvent field as an identifier, which provides a robust event identification technique that does not require static or run-time reflection. </li></ul></ul>
  24. 24. How Routed Events Are Implemented <ul><li>// Register the routed event </li></ul><ul><li>public static readonly RoutedEvent SelectedEvent = EventManager.RegisterRoutedEvent( &quot;Selected&quot;, RoutingStrategy.Bubble, typeof (RoutedEventHandler), typeof (MyCustomControl));  </li></ul><ul><li>// .NET wrapper </li></ul><ul><li>public event RoutedEventHandler Selected{ add { AddHandler(SelectedEvent, value); } remove { RemoveHandler(SelectedEvent, value); }}  </li></ul><ul><li>// Raise the routed event &quot;selected“ </li></ul><ul><li>RaiseEvent( new RoutedEventArgs(MyCustomControl.SelectedEvent)); </li></ul>
  25. 25. Routing Strategies: <ul><li>Bubbling: </li></ul><ul><ul><li>Event handlers on the event source are invoked. </li></ul></ul><ul><ul><li>Then routes to successive parent elements until reaching the element tree root. </li></ul></ul><ul><ul><li>To report input or state changes from distinct controls or other UI elements. </li></ul></ul><ul><li>Direct: </li></ul><ul><ul><li>Only the source element itself is given the opportunity to invoke handlers in response. </li></ul></ul><ul><ul><li>Analogous to the &quot;routing&quot; that Windows Forms uses for events. </li></ul></ul><ul><ul><li>unlike a standard CLR event, direct routed events support class handling. </li></ul></ul><ul><li>Tunneling: </li></ul><ul><ul><li>Event handlers at the element tree root are invoked. </li></ul></ul><ul><ul><li>Then The routed event then travels a route through successive child elements along the route, towards the node element that is the routed event source. </li></ul></ul><ul><ul><li>Compositing for a control, such that events from composite parts can be deliberately suppressed or replaced by events that are specific to the complete control. </li></ul></ul><ul><ul><li>Input events provided in WPF often come implemented as a tunneling/bubbling pair. </li></ul></ul><ul><ul><li>Tunneling events are also sometimes referred to as Preview events, because of a naming convention that is used for the pairs. </li></ul></ul>
  26. 26. Resource <ul><li>StaticResource: </li></ul><ul><ul><li>A simple way to reuse commonly defined objects and values. </li></ul></ul><ul><ul><li>Provides a value for a XAML property by substituting the value of an already defined resource. </li></ul></ul><ul><li>Static resource lookup behavior </li></ul><ul><ul><li>For the requested key within the resource dictionary defined by the element that sets the property. </li></ul></ul><ul><ul><li>Traverses the logical tree upward, to the parent element and its resource dictionary. </li></ul></ul><ul><ul><li>Application resources </li></ul></ul><ul><li>When: </li></ul><ul><ul><li>No intention of changing the value of the resource after it is referenced the first time. </li></ul></ul><ul><ul><li>Not reevaluated based on runtime behaviors such as reloading a page. So some performance benefit. </li></ul></ul><ul><ul><li>For Value of property that is not on a DependencyObject or a Freezable. </li></ul></ul><ul><ul><li>Compiled into a DLL, and packaged as part of the application or shared between applications </li></ul></ul><ul><ul><li>Creating a theme for a custom control, and are defining resources that are used within the themes. </li></ul></ul>
  27. 27. DynamicResource <ul><li>Provides a value for a XAML property by deferring that value to be a run-time reference to a resource. </li></ul><ul><li>When: </li></ul><ul><ul><li>The value of the resource depends on conditions that are not known until runtime. </li></ul></ul><ul><ul><li>Like SystemColors, SystemFonts, or SystemParameters </li></ul></ul><ul><ul><li>Creating or referencing theme styles for a custom control. </li></ul></ul><ul><ul><li>To adjust the contents of a ResourceDictionary during an application lifetime. </li></ul></ul><ul><ul><li>A forward reference may be required </li></ul></ul><ul><ul><li>The resource might not be used immediately when the page loads. </li></ul></ul><ul><ul><li>(Static resource references always load from XAML when the page loads; however, </li></ul></ul><ul><ul><li>a dynamic resource reference does not load until it is actually used.) </li></ul></ul><ul><ul><li>Applying resources to elements that might be reparented in the logical tree during application lifetime. </li></ul></ul>
  28. 28. Dynamic resource <ul><li>Dynamic resource lookup behavior </li></ul><ul><ul><li>Within the resource dictionary defined by the element that sets the property. </li></ul></ul><ul><ul><ul><li>If the element defines a Style property, the Resources dictionary within the Style is checked. </li></ul></ul></ul><ul><ul><ul><li>If the element defines a Template property, the Resources dictionary within the FrameworkTemplate is checked. </li></ul></ul></ul><ul><ul><li>Traverses the logical tree upward, to the parent element and its resource dictionary. </li></ul></ul><ul><ul><li>Application resources </li></ul></ul><ul><ul><li>Theme resource dictionary </li></ul></ul><ul><ul><li>System resources </li></ul></ul><ul><li>Merged Resource Dictionary </li></ul><ul><ul><li>A way to define the resources portion of a WPF application outside of the compiled XAML application. </li></ul></ul><ul><ul><li>(Resources can then be shared across applications) </li></ul></ul>
  29. 29. Data Binding Overview <ul><li>The process that establishes a connection between the application UI and business logic. </li></ul><ul><li>Elements can be bound to data from a variety of data sources in the form of common language runtime (CLR) objects and XML. </li></ul><ul><li>Features: </li></ul><ul><ul><li>ContentControls such as Button and ItemsControls such as ListBox and ListView have built-in functionality to enable flexible styling of single data items or collections of data items. </li></ul></ul><ul><ul><li>Sort, filter, and group views can be generated on top of the data. </li></ul></ul><ul><li>Basic Data Binding Concepts </li></ul>
  30. 30. Data Binding Overview <ul><li>Direction of the Data Flow </li></ul><ul><li>What Triggers Source Updates </li></ul>
  31. 31. Animation Overview <ul><li>Animation is an illusion that is created by quickly cycling through a series of images, each slightly different from the last. </li></ul><ul><li>WPF includes an efficient timing system that is exposed through managed code and Extensible Application Markup Language (XAML) and that is deeply integrated into the WPF framework. </li></ul><ul><li>For a property to have animation capabilities, it must meet the following three requirements: </li></ul><ul><li>It must be a dependency property. </li></ul><ul><li>It must belong to a class that inherits from DependencyObject and implements the IAnimatable interface. </li></ul><ul><li>There must be a compatible animation type available. </li></ul><ul><li>Controls such as Button and TabControl, and also Panel and Shape objects inherit from DependencyObject. </li></ul>
  32. 32. Storyboards Overview <ul><li>A Storyboard is a type of container timeline that provides targeting information for the timelines it contains. </li></ul><ul><li>A Storyboard can contain any type of Timeline, including other container timelines and animations. </li></ul><ul><li>Storyboard objects enable you to combine timelines that affect a variety of objects and properties into a single timeline tree, making it easy to organize and control complex timing behaviors. </li></ul><ul><li>How to Apply Animations with a Storyboard </li></ul><ul><ul><li>To use a Storyboard to organize and apply animations, you add the animations as child timelines of the Storyboard. The Storyboard class provides the Storyboard.TargetName and Storyboard.TargetProperty attached properties. You set these properties on an animation to specify its target object and property. </li></ul></ul><ul><ul><li>Sample Code </li></ul></ul>
  33. 33. Triggers Overview <ul><li>Represents a trigger that applies property values or performs actions conditionally. </li></ul><ul><ul><li>Example: </li></ul></ul><ul><li>WPF defines properties that correspond to end-user actions, such as the IsMouseOver property that is set to true when the user hovers the cursor over a UIElement or the corresponding IsMouseOver property of a ContentElement. Representing end-user actions in property values, along with the Trigger element, allows WPF styles to change property values based on those end-user actions, all from within markup. </li></ul><ul><ul><li>Sample Code </li></ul></ul>
  34. 34. Styles and Templates Overview <ul><li>Styling and templating refer to a suite of features (styles, templates, triggers, and storyboards) that allow an application, document, or user interface (UI) designer to create visually compelling applications and to standardize on a particular look for their product. </li></ul>
  35. 35. Trees in WPF <ul><li>The Logical Tree: </li></ul><ul><ul><li>Why: </li></ul></ul><ul><ul><li>Content models can readily iterate over their possible child elements, and so that content models can be extensible. </li></ul></ul><ul><ul><li>A framework for certain notifications, such as when all elements in the logical tree are loaded. </li></ul></ul><ul><ul><li>Resource references are resolved by looking upwards through the logical tree for Resources collections on the initial requesting element and then parent elements. </li></ul></ul>
  36. 36. Trees in WPF <ul><li>The Visual Tree </li></ul><ul><ul><li>The structure of visuals represented by the Visual base class. </li></ul></ul><ul><ul><li>When you write a template for a control, you are defining or redefining the visual tree that applies for that control. </li></ul></ul><ul><ul><li>That event routes for a routed event mostly travel along the visual tree, not the logical tree. </li></ul></ul><ul><ul><li>For Lower-level control over drawing for performance and optimization reasons </li></ul></ul><ul><li>Sample Code </li></ul>
  37. 37. Attached Events <ul><li>A handler for a particular event to an arbitrary element rather than to an element that actually defines or inherits the event. </li></ul><ul><li>Sample Code: </li></ul>
  38. 38. Input System <ul><li>Subsystem provides a powerful API for obtaining input from a variety of devices, including the mouse, keyboard, and stylus. </li></ul><ul><li>Where: </li></ul><ul><li>UIElement, ContentElement, FrameworkElement, and FrameworkContentElement Plus the Keyboard class and Mouse classes </li></ul><ul><li>For example: </li></ul><ul><li>The key down event is associated with the KeyDown and PreviewKeyDown events. </li></ul><ul><li>Preview events tunneling down the element tree from the root element to the target element. </li></ul><ul><li>Bubbling events bubbling up from the target element to the root element. </li></ul>
  39. 39. Commanding Overview <ul><li>Different from a simple event handler attached to a button or a timer that Commands separate the semantics and the originator of an action from its logic. </li></ul><ul><li>The semantics of the command are consistent across applications and classes, but the logic of the action is specific to the particular object acted upon. </li></ul><ul><li>Implement the ICommand. </li></ul><ul><li>Example Code </li></ul><ul><li>Four Main Concepts in WPF Commanding </li></ul><ul><ul><li>The command : The action to be executed. </li></ul></ul><ul><ul><li>The command source: T he object which invokes the command. </li></ul></ul><ul><ul><li>The command target: The object that the command is being executed on. </li></ul></ul><ul><ul><li>The command binding: The object which maps the command logic to the command. </li></ul></ul><ul><ul><li>The Paste command is the command, the MenuItem is the command source, the TextBox is the command target, and the command binding is supplied by the TextBox control. </li></ul></ul><ul><li>Commands </li></ul><ul><ul><li>By implementing the ICommand interface. </li></ul></ul><ul><ul><li>ICommand exposes two methods, Execute, and CanExecute, and an event, CanExecuteChanged. </li></ul></ul><ul><ul><li>Similar to Routedevents, there are RoutedCommand  </li></ul></ul>
  40. 40. Commanding Overview <ul><li>Command Sources: </li></ul><ul><ul><li>The object which invokes the command </li></ul></ul><ul><ul><li>Examples: MenuItem, Button, and KeyGesture. </li></ul></ul><ul><ul><li>Implement the ICommandSource interface. </li></ul></ul><ul><ul><li>ICommandSource exposes three properties: Command, CommandTarget, and CommandParameter. </li></ul></ul><ul><li>CommandBinding: </li></ul><ul><ul><li>Associates a command with the event handlers that implement the command. </li></ul></ul><ul><ul><li>The CommandBinding class contains a Command property, and PreviewExecuted, Executed, PreviewCanExecute, and CanExecute events. </li></ul></ul><ul><li>Example Code </li></ul><ul><li>Command Library </li></ul><ul><li>ApplicationCommands, NavigationCommands, MediaCommands, EditingCommands, and the ComponentCommands. </li></ul><ul><li>Creating Custom Commands </li></ul><ul><li>Example Code </li></ul>
  41. 41. References: <ul><li>http://msdn.microsoft.com </li></ul><ul><li>http://windowsclient.net </li></ul><ul><li>http://www.wpftutorial.net </li></ul><ul><li>http://joshsmithonwpf.wordpress.com </li></ul><ul><li>http://idealprogrammer.com </li></ul><ul><li>http://www.msdev.com </li></ul><ul><li>http://www.wpfdev.com </li></ul><ul><li>http:// WPFpedia .com </li></ul>
  42. 42. <ul><li>A soft copy will be available at: </li></ul><ul><li>http://softarchitect.wordpress.com </li></ul><ul><li>For Future discussion, join </li></ul><ul><li>http://tech.groups.yahoo.com/group/SoftArchitect/ </li></ul>
  43. 43. <ul><li>If you want to master a technology, start teaching it to others. </li></ul>