Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add GestureListener handler to a control in cs code in silverlight?

I don’t understand how to use some features from Windows Phone Toolkit in cs code in Silverlight (more precise, I don’t understand how to use GestureListener). I saw many examples of using GestureListener in xaml like this

<Image Source="something.jpg">
    <toolkit:GestureService.GestureListener>
        <toolkit:GestureListener Tap="image_Tap" Hold="image_Hold" />
    </toolkit:GestureService.GestureListener>
</Image>

And this works fine, but I create images dynamically and want dynamically add gesture handlers in cs code. Can someone give an example how to do the same thing only in cs code?

like image 263
max Avatar asked Sep 21 '10 01:09

max


2 Answers

SetGestureListener was deprecated , that`s right, instead you can use GetGestureListener like this

var gl = GestureService.GetGestureListener(img);
gl.DoubleTap += new EventHandler<GestureEventArgs>(GestureListenerDoubleTap);
like image 153
max Avatar answered Oct 22 '22 04:10

max


Attached properties typically have a SetPropertyName and GetPropertyName method pair that correspond to the above XAML. I don't have experience with the Windows Phone 7 specifically, but the above would probably be done as:

GestureService.SetGestureListener(myImage, new GestureListener {
    Tap = "image_Tap",
    Hold = "image_Hold"
});

If those Tap and Hold properties are images, you will need to load some BitmapImage objects programmatically instead of strings.

like image 34
Josh Avatar answered Oct 22 '22 03:10

Josh