简体   繁体   中英

How do i set event handler to a control?

I am new to windows 8 app development using xaml and c#. I created a new image using.

  Image img = new Image();

I successfully added the image to the canvas, but i want to add an eventhandler pointerpressed to the img. How do i do it?

You have your Image instance in code

Image img = new Image();

And I'm presuming you've added it to your Canvas also in code, so the logical place to hook your event in code

Image img = new Image();
img.PointerPressed += Image_PointerPressed;

Where you have defined the Image_PointerPressed elsewhere in that same class

private void Image_PointerPressed(object sender, PointerRoutedEventArgs e)
{
    // do what you want here...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM