Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

c# - passing Event Arguments of original handler to Routed Event in wpf -


the following code shows normal event , routed event. here have used same event name explaining purposes in reality using routed event.

//normal event public event selectedhandler selected; public delegate void selectedhandler(object sender, routedeventargs e);  //routed event public static readonly routedevent selectedevent = eventmanager.registerroutedevent( "selected", routingstrategy.bubble, typeof(routedeventhandler), typeof(myusercontrol));  //add remove handlers public event routedeventhandler selected {     add { addhandler(selectedevent, value); }     remove { removehandler(selectedevent, value); } } 

i raising these events couple of event handlers follows

private void lstvmyview_selectionchanged(object sender, selectionchangedeventargs e) {     //normal event raise     if (selected != null)         selected(this, e);      //routed event raise     routedeventargs args = new routedeventargs(selectedevent);     raiseevent(args); }  private void lstvmyview_mouseleftbuttonup(object sender, mousebuttoneventargs e) {     //normal event raise     if (selected != null)         selected(this, e);      //routed event raise     routedeventargs args = new routedeventargs(selectedevent);     raiseevent(args); } 

when handling normal event able send args of both handlers event in routed event args new instance. want pass args of both handlers routed event. possible achieve this? if yes how?

first of not need (and should remove it):

//normal event public event selectedhandler selected; public delegate void selectedhandler(object sender, routedeventargs e); 

i.e. not need define separate "normal" event, because have done declaration:

public event routedeventhandler selected {     add { addhandler(selectedevent, value); }     remove { removehandler(selectedevent, value); } } 

with above code block "wrapping" routed event "normal" (clr) 1 users of class can use "normal" syntax (i.e. instanceofmyusercontrol.selected += ....)

second, if want event arguments of routed event same ones of selectionchanged event of the listview listening to, should declare routed event way:

public static readonly routedevent selectedevent = eventmanager.registerroutedevent( "selected", routingstrategy.bubble, typeof(selectionchangedeventhandler), typeof(myusercontrol));  //add remove handlers public event selectionchangedeventhandler selected {     add { addhandler(selectedevent, value); }     remove { removehandler(selectedevent, value); } } 

notice have substituted routedeventhandler selectionchangedeventhandler, predefined 1 can "carry" selectionchangedeventargs.

now rising of event. not need rise both "normal" , routed 1 (as "normal" wrapper routed), should delete this:

//normal event raise if (selected != null)     selected(this, e); 

and rise routed version, can done way:

selectionchangedeventargs args =      new selectionchangedeventargs(selectedevent, e.removeditems, e.addeditems);  raiseevent(args); 

notice using event arguments original event set addeditems , removeditems of 1 custom one.


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -