views:

104

answers:

3

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?

+1  A: 

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.

Josh Einstein
A: 

Looks like SetGestureListener is now depreciated. What now?

:D

Roger Guess
A: 

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

var gl = GestureService.GetGestureListener(img);
gl.DoubleTap += new EventHandler<GestureEventArgs>(GestureListenerDoubleTap);
max