Sys
Sys

Reputation: 413

WPF - Override event

I'm inheriting a third party control and need to add steps for some events.

My old xaml:

<ThirdPartyControl Sorting="ThirdPartyControl_Sorting" />

My new xaml:

<MyInheritedControl Sorting="ThirdPartyControl_Sorting" />

In my inherited control i would implement the new steps and route the event back normally. How can i do this?

Upvotes: 0

Views: 821

Answers (2)

Pavlo Glazkov
Pavlo Glazkov

Reputation: 20746

Does your third party control provide protected and virtual OnSorting method? If so, you can override it and do whatever you want and then call base implementation:

protected override OnSorting(SortingEventArgs e)
{
   // Do your thing

   base.OnSorting(e);
}

Upvotes: 2

TalkingCode
TalkingCode

Reputation: 13557

With base you can always call the parent class from a inherited (child) object:

        void Init()
        {
            base.Init();
        }

Like you said you have to route the event back to the parent. But I don't think it can be done in XAML directly. You can even pass on method parameters:

        void Init(int value)
        {
            base.Init(value);
        }

Upvotes: 0

Related Questions