In my project, I want to override Touchup Event Handler which is build in the WPF. I do not know how to override this event handler for my own use. Is that possible? Someone could give some examples, I do not get some references or example about it.
-
Which event are you trying to override? – Chase Ernst Feb 04 '15 at 15:59
-
such as Touchup, TouchDown – user2137886 Feb 04 '15 at 16:06
-
Have you tried something like this? http://stackoverflow.com/questions/5774849/how-to-override-onclose-event-on-wpf – Chase Ernst Feb 04 '15 at 16:07
-
1@user2137886 can you explain what do you mean by _override this event handler for my own use_ – dkozl Feb 04 '15 at 16:07
-
@ChaseErnst I think it is different with that. it should involve custom evenArgs. – user2137886 Feb 04 '15 at 16:10
-
@dkozl for example, I want to pass some my own parameters and get some – user2137886 Feb 04 '15 at 16:11
-
Are you able to create a method to call within that event handler maybe? – Chase Ernst Feb 04 '15 at 16:12
2 Answers
You can create a custom control and override the events. refer the below code i tried for TextBox control.
class TextBoxEx : TextBox
{
protected override void OnTouchUp(System.Windows.Input.TouchEventArgs e)
{
base.OnTouchUp(e);
}
protected override void OnTouchDown(System.Windows.Input.TouchEventArgs e)
{
base.OnTouchDown(e);
}
}

- 5,348
- 1
- 22
- 44
It is possible.
Let's say you want to override this TouchUp event (Completely override it). You will need to define a new function to handle this. Something like :
private void Custom_TouchUp(object sender, TouchEventArgs e)
{
// Do some stuff there
}
(It may not be TouchEventArgs, I haven't tried it, but it looks like it)
Then, in your xaml, in your object definition, you need to specify to the targeted object that it should use this function. If it's a combobox (for example), you'll have something like this :
<Combobox [...] TouchUp=Custom_TouchUp>
<Eventual parameters>
</Combobox>
And voila! Your object will use your new function.
Now, let's say you just want to alter a tiny bit the current event, then you can just override the OnTouchUp function that will be called when the event occurs. Something like this should do :
public override void OnTouchUp()
{
base.OnTouchUp();
// Other stuffs
}
But then, every element of the same class will act the same. So that's really useful when you want to define a new custom class

- 1,535
- 2
- 11
- 17