4

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.

user2137886
  • 61
  • 1
  • 7

2 Answers2

3

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);
    }
}
Ayyappan Subramanian
  • 5,348
  • 1
  • 22
  • 44
0

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

Dimitri Mockelyn
  • 1,535
  • 2
  • 11
  • 17