KEMBAR78
Introduction to WPF | PPSX
WPF - Introduction
            By: Munish Arora
    munish.arora@gmail.com
What is WPF?
  It is a new foundation for building Windows-based applications by
  using:
   • Media

   • Documents

   • Application UI


   Windows                            Windows
   Presentation                       Workflow
   Foundation                         Foundation
   (WPF)                              (WF)
                      Windows
                      Communication                Windows
                      Foundation                   CardSpace
                      (WCF)                        (WCS)


  .NET Framework 4.0
WPF Architecture
  WPF Core Components                                         Provides the
                                                          presentation classes
                                                           that you use as a
                                                               developer
                PresentationFramework
 Managed Code                                             Provides a managed
                 PresentationCore                       wrapper for milcore and
                                                        implements much of the
                                                         underlying functionality
                 Common Language Runtime                         of WPF

                                         milcore       Unmanaged Code

                 User32                 DirectX
                                                        Written in UnManaged
Low level API                                           code in order to enable
 for handling            DirectX enables all display     tight integration with
 user actions               handling in WPF, and        DirectX. It renders each
                        provides efficient hardware        WPF element on a
                          and software rendering            DirectX surface
WPF
• WPF allows using both uses declarative language such as XAML and
  programming language (such has C#) to provide behavior




• When you add an element in XAML, the WPF runtime instantiates
  the object in the same way that you would programmatically
  instantiate an object in the code-behind file.
WPF Application Types




  Stand-Alone Applications   XAML Browser Applications (XBAPs)

  You use this type of              You use this type of
    application when               application when your
   you require access             application can run with
  to system resources                limited permission
Creating a Simple WPF Application
In this demonstration, you will see how to
• Create a stand-alone WPF application
• Create a browser application
• Add controls to your application
Routed Events
•   Routed events are a new concept to most developers. In good old fashioned
    .NET 1.x/2.0, we all probably used some custom events or hooked some
    delegates onto some existing event, such as:

private System.Web.Forms.Button button1;
button1.click+=new EventHandler(button1_Click);
...
private void button1_Click(object sender, EventArge e)
{
    //Click Event seen, so something about it
}
Routed Events
•   When you create an application that has user interface, your application uses
    events to respond to user actions. E.g. when user clicks button, then it fires
    and event. So, corresponding code can be written to handle the events.
    These events thus define the behavior of application.

•   In WPF the elements are arranged in hierarchical order known as element
    tree. e.g.




•   Here StackPanel container control is inside the Windows element and Button
    controls are inside the StackPanel. Routed events are similar to events but
    their notification can move up or down the hierarchy tree.
Routed Events
•   There are three types of event notification methods, namely:

     – Bubbling: Allows events to bubble up the VisualTree (the tree of Visual
       UI Elements), to the root element.

     – Tunneling: Allows events to tunnel down the VisualTree.

     – Direct: Works just like the old .NET 1.x/2.0 CLR events. Only the
       subscriber gets to see the event. The one we see above is Direct event
       notification
Routed Events - Example
•   In this example, we will see how Routing works. Such that when button is
    clicked, the event goes to the container which may handle this.
     – Steps:
         • Add a StackPanel in the Grid
         • Add buttons to stack panel
         • Add a label in Grid
         • Now add an EventHandler for click in StackPanel, such that when
           button is clicked, label should display that this button has been
           clicked
         • Then we will add another button via code and check that if this newly
           added button is clicked, does it work in a similar way?
Navigation Capabilities
• Let us create a XABP (XAML Browser Application)
   – Where-in you can browse from one page to other page and vice-versa
THANK YOU!

Introduction to WPF

  • 1.
    WPF - Introduction By: Munish Arora munish.arora@gmail.com
  • 2.
    What is WPF? It is a new foundation for building Windows-based applications by using: • Media • Documents • Application UI Windows Windows Presentation Workflow Foundation Foundation (WPF) (WF) Windows Communication Windows Foundation CardSpace (WCF) (WCS) .NET Framework 4.0
  • 3.
    WPF Architecture WPF Core Components Provides the presentation classes that you use as a developer PresentationFramework Managed Code Provides a managed PresentationCore wrapper for milcore and implements much of the underlying functionality Common Language Runtime of WPF milcore Unmanaged Code User32 DirectX Written in UnManaged Low level API code in order to enable for handling DirectX enables all display tight integration with user actions handling in WPF, and DirectX. It renders each provides efficient hardware WPF element on a and software rendering DirectX surface
  • 4.
    WPF • WPF allowsusing both uses declarative language such as XAML and programming language (such has C#) to provide behavior • When you add an element in XAML, the WPF runtime instantiates the object in the same way that you would programmatically instantiate an object in the code-behind file.
  • 5.
    WPF Application Types Stand-Alone Applications XAML Browser Applications (XBAPs) You use this type of You use this type of application when application when your you require access application can run with to system resources limited permission
  • 6.
    Creating a SimpleWPF Application In this demonstration, you will see how to • Create a stand-alone WPF application • Create a browser application • Add controls to your application
  • 7.
    Routed Events • Routed events are a new concept to most developers. In good old fashioned .NET 1.x/2.0, we all probably used some custom events or hooked some delegates onto some existing event, such as: private System.Web.Forms.Button button1; button1.click+=new EventHandler(button1_Click); ... private void button1_Click(object sender, EventArge e) { //Click Event seen, so something about it }
  • 8.
    Routed Events • When you create an application that has user interface, your application uses events to respond to user actions. E.g. when user clicks button, then it fires and event. So, corresponding code can be written to handle the events. These events thus define the behavior of application. • In WPF the elements are arranged in hierarchical order known as element tree. e.g. • Here StackPanel container control is inside the Windows element and Button controls are inside the StackPanel. Routed events are similar to events but their notification can move up or down the hierarchy tree.
  • 9.
    Routed Events • There are three types of event notification methods, namely: – Bubbling: Allows events to bubble up the VisualTree (the tree of Visual UI Elements), to the root element. – Tunneling: Allows events to tunnel down the VisualTree. – Direct: Works just like the old .NET 1.x/2.0 CLR events. Only the subscriber gets to see the event. The one we see above is Direct event notification
  • 10.
    Routed Events -Example • In this example, we will see how Routing works. Such that when button is clicked, the event goes to the container which may handle this. – Steps: • Add a StackPanel in the Grid • Add buttons to stack panel • Add a label in Grid • Now add an EventHandler for click in StackPanel, such that when button is clicked, label should display that this button has been clicked • Then we will add another button via code and check that if this newly added button is clicked, does it work in a similar way?
  • 11.
    Navigation Capabilities • Letus create a XABP (XAML Browser Application) – Where-in you can browse from one page to other page and vice-versa
  • 12.