c# - In a Control extension, Override or addHandler? -
c# - In a Control extension, Override or addHandler? -
i created extension datagrid. know improve way thing in event.
is improve add together handler :
class mydatagrid : datagrid { public mydatagrid() { this.previewkeydown+= mydatagrid_previewkeydown; } protected void mydatagrid_previewkeydown(/* args */) {/* stuff */} }
or override this:
class mydatagrid : datagrid { public mydatagrid() { } protected override void onpreviewkeydown(/* args */) {/* stuff */} }
and if allow base.onpreviewkeydown(e);
in override, same eventhandler?
it not matter either way. said, should override method -- whole purpose handle event within control. if add together event handler, needlessly adding method event's invocation list (ie, slight performance hit).
if want strict/fanatical performance, create "mydatagrid" class "sealed".
sealed class mydatagrid : datagrid { ... }
that allows compiler/runtime determine doesn't need check overrides of virtual method "onpreviewkeydown" above "mydatagrid" class.
c# wpf
Comments
Post a Comment