c# - Should I create a new method to handle the event or override the base method? -


i'm using class derived uielement class when writing uwp program using c#, want include handling input controls such mouse , keyboard actions. see there virtual methods says onsomeevent() , can override these method fit handling process, or can create new method handling public events defined in base class, , subscribe them these input events in constructor. assume these 2 methods both work i hope know more professional or more advisable way of doing this, , why. explain why ms offers these 2 ways @ same time.

here's events , methods of uielement class https://msdn.microsoft.com/en-us/library/system.windows.uielement(v=vs.110).aspx#examples

and paragraph of quoting

uielement provides starting point element layout characteristics, , exposes virtual methods derived classes can override, can influence layout rendering behavior of element , child elements. of input , focusing behavior elements in general defined in uielement class. includes events keyboard, mouse , stylus input, , related status properties. many of these events routed events, , many of input-related events have both bubbling routing version tunneling version of event. these paired events typically events of greatest interest control authors.

in derived class, override existing method.

why? event handler less reliable override method. example, external classes can clear event handlers, can't change code in override. have seal own class though, or method may overridden.

another point consider this: want change way control works? have have control on exact execution moment of code (let's before code of base class, after, or instead of)? if so, have use override.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -