WPF Guru<br />Award(s)Microsoft C# MVP 2009<br />Codeproject MVP 2009<br />Microsoft C# MVP 2008<br />Codeproject MVP 2008...
Configuring events & event handling<br />Chapter 2.1<br />
Configuring events & event handling<br />Traditional Events still exists in WPF.<br />Routed Events (new):<br />Can be rai...
Configuring events & event handling<br />Bubbling<br />When user clicks on label<br />MouseDown<br />raised in Window<br /...
Configuring events & event handling<br />Tunneling<br />When user click on label<br />PreviewMouseDown<br />raised in Wind...
Configuring events & event handling<br />Demo <br /><ul><li>Display Bubbling + Tunneling Events (raise orders)
RoutedEventArgs
e.handled = true
e.OriginalSource & e.Source
e.RoutedEvent</li></li></ul><li>Configuring events & event handling<br />RoutedEventArgs<br />Handled, OriginalSource, Sou...
Configuring events & event handling<br />Attaching an Event Handler<br /><Button Click=“button1_click”>Btn</Button><br />A...
Configuring events & event handling<br />EventManager Class<br />GetRoutedEvents<br />Returns array contains all registere...
Upcoming SlideShare
Loading in …5
×

WPF Events

1,347 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,347
On SlideShare
0
From Embeds
0
Number of Embeds
17
Actions
Shares
0
Downloads
23
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

WPF Events

  1. 1. WPF Guru<br />Award(s)Microsoft C# MVP 2009<br />Codeproject MVP 2009<br />Microsoft C# MVP 2008<br />Codeproject MVP 2008<br />C#April 2009<br />C#Feb 2009<br />Overall Feb 2009<br />Overall Jan 2009<br />C# Oct 2008<br />C# Feb 2008<br />C# Jan 2008<br />VS2008 comp 2007, runner up<br />C# Nov 2007<br />3rd Biweekly VS2008 comp 2007<br />1st Biweekly VS2008 comp 2007<br />C# .NET July 2007<br />ASP .NET May 2007<br />C# March 2007<br />I was awarded the "Best IT project for 2006" award, at Sussex University, for my final year degree project, by the British Computer Society.<br />SachaBarber<br />WPF: A Beginner's Guide - Part 1 of n<br />Fun With Physics<br />WPF Diagram Designer - Part 3<br />XPlorerBar: A WPF Windows XP Style Explorer Bar Control<br />Simplifying the WPF TreeView by Using the ViewModel Pattern<br />
  2. 2. Configuring events & event handling<br />Chapter 2.1<br />
  3. 3. Configuring events & event handling<br />Traditional Events still exists in WPF.<br />Routed Events (new):<br />Can be raised by multiple controls.<br />Handled by multiple handlers.<br />Add multiple levels of complexity & sophistication to your UI.<br />Types of Routed Events<br />Direct Events: like “MouseLeave”.<br />Bubbling Events: like “MouseDown”.<br />Tunneling Events: like “PreviewMouseDown”.<br />
  4. 4. Configuring events & event handling<br />Bubbling<br />When user clicks on label<br />MouseDown<br />raised in Window<br />3<br />MouseDown<br />raised in Grid<br />2<br />MouseDown<br />raised in label<br />1<br />
  5. 5. Configuring events & event handling<br />Tunneling<br />When user click on label<br />PreviewMouseDown<br />raised in Window<br />1<br />PreviewMouseDown<br />raised in Grid<br />2<br />PreviewMouseDown<br />raised in Label<br />3<br />
  6. 6. Configuring events & event handling<br />Demo <br /><ul><li>Display Bubbling + Tunneling Events (raise orders)
  7. 7. RoutedEventArgs
  8. 8. e.handled = true
  9. 9. e.OriginalSource & e.Source
  10. 10. e.RoutedEvent</li></li></ul><li>Configuring events & event handling<br />RoutedEventArgs<br />Handled, OriginalSource, Source, RoutedEvent.<br />Other Args Inherited from RoutedEventArgs<br />KeyboardEventArgs = EventArgs + KeyStrokes.<br />MouseEventArgs = EventArgs + State of the Mouse.<br />
  11. 11. Configuring events & event handling<br />Attaching an Event Handler<br /><Button Click=“button1_click”>Btn</Button><br />Attached Events:<br /><Grid ButtonBase.Click=“button1_click”><br /><Button>Btn</Button></Grid><br />Me.AddHandler(Button.ClickEvent, _ New RoutedEventHandler(AddressOfClickMethod)) <br />
  12. 12. Configuring events & event handling<br />EventManager Class<br />GetRoutedEvents<br />Returns array contains all registered routed events in the App.<br />GetRoutedEventsForOwner<br />Returns array contains all registered routed events for a specific element.<br />RegisterRoutedEvent<br />Register Instance-level event handler.<br />RegisterClassHandler<br />Register Class-level event handler.<br />
  13. 13. Configuring events & event handling<br />Demo <br />Create Custom Routed Event<br />
  14. 14. How to use EventManager.RegisterRoutedEvent<br />Sample<br />http://www.codeproject.com/KB/WPF/WPFAjaxStyleComboBox.aspx.<br />
  15. 15. Configuring events & event handling<br />Creating Class-Level Event Handler<br />Using EventManger.RegisterClassLevelHandler.<br />Raised before Instance Level Events.<br />Application Level Events. (Application.vb)<br />

×