Sunday, March 27, 2016

WPF Custom Control RoutedEvent --Inject into Event System

WPF Event system is called RoutedEvent: direct, bubble up, tunnel(preview)

How WPF set up its event system
every  up the visual tree see Button_click event
and set e.Handled=true. to Ignore handled=true, Win Ctor() {
AddHandler(Button.ClcikEvent, new RountedEvent(Win_cliked), true) 
true means ignore e.handled=true anywhere along the tree

Use Snippet for Building Custom Routed event 
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC#\Snippets\1033\Visual C# 
and C:\Users\jimmy\Documents\Visual Studio 2015\Code Snippets are snippet storage
do not edit them,use VS2015->Tools->Snippt Mgr->add/import from HomeLab16\tools
store download copy paste xml in HomeLab16\tools change shortcut in xml to proprevt

Snippet will put static RE,add/remove EventMgr,Bubble onto CustomControl

  proected virtual RaiseMyEventFromCtl() { //to allow future override
  RaiseEvent(new RountedEventArgs(CustCtl.MyEvent));} 
Custom eventarg--eventarg additional param 
delegate void CustRoutedEvenHander(object,CustRoutedEventArgs);
class CustRoutedEventArgs: RoutedEventArgs ctor(RoutedEvent re, param):base(re)

Usage <myCC  CustEvent="" />  // now CustEvt is walk up/down trees

No comments:

Post a Comment