1
votes

This is a Windows Phone 7 Silverlight app. I have an ItemsControl that is displaying a scrolling list. I'm using a Grid as the container in the ItemTemplate. I want to capture a click event (touch) on the Grid to navigate to a details view for the item clicked. However, the only events I see available to me are mouse events that are also being used in scrolling. I'm more familiar with Android programming in which the framework differentiates a scroll event and a click event for me. How do I do the same on WP7? I want to ignore touch events when they're associated with scrolling but capture click events that are actual clicks by the user. The manual way is to handle MouseLeftButtonUp and just set a flag when scrolling that tells me to ignore the event, but I'd love to avoid having to write that myself every time I need to display a list. I would think this is a very common use case that has an easy solution.

SOLUTION

Matt's answer below worked, but here's a full description of how I got it to work for those who google this in the future.

  1. Download and install Silverlight Toolkit for WP7: http://silverlight.codeplex.com/releases/view/60291
  2. Add reference to Microsoft.Phone.Controls.Toolkit.dll in project
  3. Include the toolkit namespaces
  4. Add a GestureListener to the item that should receive tap events:

Namespaces to add to pages and controls that need this functionality:

xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit" 
xmlns:toolkitPrimitives="clr-namespace:Microsoft.Phone.Controls.Primitives;assembly=Microsoft.Phone.Controls.Toolkit"

Updated list xaml (abbreviated):

        <ItemsControl ItemsSource="{Binding FeedItems}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>

                    <!-- Container -->
                    <Grid HorizontalAlignment="Stretch">
                        <toolkit:GestureService.GestureListener>
                            <toolkit:GestureListener
                                Tap="OnFeedItemTap" />
                        </toolkit:GestureService.GestureListener>
1

1 Answers

1
votes

If you're using the latest tools/targetting 7.1 (mango) devices then you can use the Tap event on the Grid.

If you're still targetting 7.0 then you could use the Click event or use the GestureListener in the Toolkit to detect taps.