locked
Problem detecting Swipe gesture RRS feed

  • Question

  • Hi

    I have been looking for sample code for the gesture recognizer detecting crosssliding swipes however I have not found much, I have tried coding a test setup to try to detect but not having much luck as it seem the crossslide event never fires.. can someone help me with this?

    my xaml

    <Grid Background="{StaticResource ApplicationPageBackgroundBrush}">
            <Image x:Name="imgBackground" Source="Assets/Hope_Wallpaper.jpg" Stretch="Fill"></Image>
    
            <Viewbox x:Name="vbCalendar" Stretch="UniformToFill" 
                     PointerPressed="Swipe_PointerPressed" 
                     PointerMoved="Swipe_PointerMoved" 
                     PointerReleased="Swipe_PointerReleased">
                <!-- Horizontal scrolling grid used in most view states -->
    
                <StackPanel Margin="25,30,0,0">
                        <StackPanel>
                          
                            <StackPanel Margin="100,0,0,0">
                                     <TextBlock x:Name="lbMonth" Grid.Column="1" Text="" Style="{StaticResource PageHeaderTextStyle}"/>
                                 </StackPanel>
                             
                          </StackPanel>
                   </StackPanel>
         </Viewbox>
    </Grid>
    
    
    C#
    
            public MainPage()
            {
                this.InitializeComponent();
    
                gr = new GestureRecognizer();
                gr.GestureSettings = GestureSettings.CrossSlide;
                gr.CrossSliding += new TypedEventHandler<GestureRecognizer, CrossSlidingEventArgs>(gr_CrossSliding);
    
                SetCalendarDates();
            }
    
            void gr_CrossSliding(GestureRecognizer sender, CrossSlidingEventArgs args)
            {
                SetToastNot("Swipe detected");
            }
    
            private void Swipe_PointerPressed(object sender, Windows.UI.Xaml.Input.PointerEventArgs e)
            {
                gr.ProcessDownEvent(e.GetCurrentPoint(vbCalendar));
            }
    
            private void Swipe_PointerMoved(object sender, Windows.UI.Xaml.Input.PointerEventArgs e)
            {
                gr.ProcessMoveEvents(e.GetIntermediatePoints(vbCalendar));
            }
    
            private void Swipe_PointerReleased(object sender, Windows.UI.Xaml.Input.PointerEventArgs e)
            {
                gr.ProcessUpEvent(e.GetCurrentPoint(vbCalendar));
            }
    
    
            private void SetToastNot(string message)
            {
                IToastNotificationContent toastContent = null;
                IToastText01 templateContent = ToastContentFactory.CreateToastText01();
                templateContent.TextBodyWrap.Text = message;
                toastContent = templateContent;
    
                ToastNotification toast = toastContent.CreateNotification();
                ToastNotificationManager.CreateToastNotifier().Show(toast);
            }


    Juan Rodriguez Celltrac Software

    Wednesday, May 16, 2012 11:20 PM

Answers

  • Hi Juan,

    If you only want select and not rearrange then set RearrangeStart to 0. You can also set the speed bump values to 0 since you don't need to warn the user that they're about to pull the item out of place.

    For the swipe detection, pass in PointerPoints relative to your window rather than to the child element. You can limit the swipe to only cover the element by looking at the Pointer events' sender object or by hit testing to determine which element the pointer events are over before sending them to the GestureRecognizer.

    --Rob

    • Marked as answer by Min ZhuMember Wednesday, May 30, 2012 1:59 AM
    Monday, May 21, 2012 9:58 PM
    Moderator

All replies

  • is there anyone who has experience with the gesture recongnizer that  know's much about this? 


    Juan Rodriguez Celltrac Software

    Thursday, May 17, 2012 2:55 PM
  • Try setting the CrossSlideThresholds

    .--Rob

    Thursday, May 17, 2012 3:32 PM
    Moderator
  • Thanks Rob for the reply and I have a question as to a better understanding to the values for CrossSlideThresholds as there seems to be no examples I do see it is based on swipe vs slide but not sure what the values are 1 vs the other can you explain more on this?

    Juan Rodriguez Celltrac Software


    There seems to be no examples on this anywhere which would help out alot... 
    • Edited by rruffman07 Thursday, May 17, 2012 3:58 PM
    Thursday, May 17, 2012 3:49 PM
  • Which part is unclear to you? If you can clarify what you need help with I can try to answer that.

    The CrossSlideThresholds structure documentation has a graphic which describes all of the values. There is a more in depth description in the Guidelines for cross-slide documentation.

    --Rob

    Thursday, May 17, 2012 11:53 PM
    Moderator
  • Hi Rob

    What I am not understanding is the values part I am not trying to move objects so the RearrangeStart, SelectionStart, speed bump etc.. I am not sure what to use here I just need to know if a user swipes and if its the swipe was a left swipe or a right swipe. Please excuse my not knowing but I developed in windows phone and there was a gesture listener that would give us these values and we did not have to setup thresholds...

    here is what I have so far and the values I have do not represent anything official but I was just adding some values to test to see if the crosssliding event would fire and it didn't maybe you could just correct my code to what it should be for me to get the results I am looking for?

    public MainPage()
            {
                this.InitializeComponent();
                CrossSlideThresholds cst = new CrossSlideThresholds();
                cst.RearrangeStart = 10;
                cst.SelectionStart = 12;
                cst.SpeedBumpStart = 12;
                cst.SpeedBumpEnd = 24;
                gr = new GestureRecognizer();
                gr.GestureSettings = GestureSettings.CrossSlide;
                gr.CrossSlideHorizontally = true;
                gr.CrossSlideThresholds = cst;
                gr.CrossSliding += new TypedEventHandler<GestureRecognizer, CrossSlidingEventArgs>(gr_CrossSliding);
                
            }
    void gr_CrossSliding(GestureRecognizer sender, CrossSlidingEventArgs args)
            {
                SetToastNot("Swipe detected");
            }
            private void Swipe_PointerPressed(object sender, Windows.UI.Xaml.Input.PointerEventArgs e)
            {
                gr.ProcessDownEvent(e.GetCurrentPoint(vbCalendar));
            }
            private void Swipe_PointerMoved(object sender, Windows.UI.Xaml.Input.PointerEventArgs e)
            {
                gr.ProcessMoveEvents(e.GetIntermediatePoints(vbCalendar));
            }
            private void Swipe_PointerReleased(object sender, Windows.UI.Xaml.Input.PointerEventArgs e)
            {
                gr.ProcessUpEvent(e.GetCurrentPoint(vbCalendar));
            }

       


    Juan Rodriguez Celltrac Software

    Friday, May 18, 2012 6:37 PM
  • Hi Rob

    can you help with my last request?


    Juan Rodriguez Celltrac Software

    • Proposed as answer by Maciej Grabek Wednesday, February 26, 2014 8:33 PM
    • Unproposed as answer by Maciej Grabek Wednesday, February 26, 2014 8:33 PM
    Monday, May 21, 2012 6:37 PM
  • Hi Juan,

    If you only want select and not rearrange then set RearrangeStart to 0. You can also set the speed bump values to 0 since you don't need to warn the user that they're about to pull the item out of place.

    For the swipe detection, pass in PointerPoints relative to your window rather than to the child element. You can limit the swipe to only cover the element by looking at the Pointer events' sender object or by hit testing to determine which element the pointer events are over before sending them to the GestureRecognizer.

    --Rob

    • Marked as answer by Min ZhuMember Wednesday, May 30, 2012 1:59 AM
    Monday, May 21, 2012 9:58 PM
    Moderator
  • Is your Pointer events fired? I had to do drag n drop and my main problem was that. Override the OnPointer... events like this:

    protected override void OnPointerMoved(Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
            {
                base.OnPointerMoved(e);
                e.Handled = false;
            }




    • Edited by essigzso Thursday, July 19, 2012 3:18 PM
    Thursday, July 19, 2012 3:17 PM