2

I have created a new UIElement that derives from Systen.Windows.Controls.Canvas.

I am trying to handle flicks made on this object.

Everything is done in C#, in code (no XAML) using the Silverlight Phone Toolkit (February version as I want to target 7.0)

In my object constructor I do:

        //Create gesture handling
        gl = GestureService.GetGestureListener(this);
        gl.Flick += new EventHandler<FlickGestureEventArgs>(gl_Flick);

and gl_Flick is simply:

    void gl_Flick(object sender, FlickGestureEventArgs e)
    {
        if (e.HorizontalVelocity >= 0)
        {
            // Right swipe (flick)
            if (gotSwipe != null)
            {
                gotSwipe(this, e);
            }
        }
    }

Now, in the constructor, I also create and add a few TextBlocks

For some reason, the flick is only generating an event if done over one of those TextBocks. If I do the flick on any of the empty area of the Canvas nothing occurs. As I can't find any documentations related to the Silverlight toolkit, everything has been done via trials&errors.

How could I do, so the flick will be recognised when performed anywhere over this canvas and not limited to over the children it contains?

1
  • Are there any other event handlers on the canvas? Commented Oct 22, 2011 at 12:19

1 Answer 1

4

I'm more focused towards WPF, but the way you talk about it reminds me of the classic null background issue.

The solution: set a non null background for your canvas.

EDIT: something like

myCanvas.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 1));
4
  • 1
    It's the same problem for Windows Phone, he'll have to set the background to Transparent (or any other colour, but x:Null), to get touch-input on any FrameworkElement. Commented Oct 22, 2011 at 12:31
  • In WPF, Transparent can be tricky sometimes. I prefer to use something like #01000001 Commented Oct 22, 2011 at 13:13
  • Works fine on Windows Phone :) <Canvas Background="Transparent"></Canvas> Commented Oct 22, 2011 at 13:23
  • Thanks, it was exactly the problem: adding this.Background = new SolidColorBrush(Colors.Transparent); fixed it.
    – jyavenard
    Commented Oct 22, 2011 at 22:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.