0

Because Hold And Tap Event is not available in UWP so i am using Tapped And Holding event in UWP.

for Windows phone 8 apps i am using tap hand hold event for button. where when i hold a button tap event is not fire.

but in UWP i tried Click and Tapped event but both fires when i hold button.

please suggest me other method where other event should not fire when i hold a button Holding Event here is necessary, suggest me alternate of Tapped and click event because these event fires when i hold and release a button

XAML

<StackPanel Grid.Column="0" Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Center">
       <Button Name="BackwardButton" 
               FontFamily="Segoe MDL2 Assets" Content="&#xE26C;"
               FontSize="30" Background="Transparent"
               Tapped="BackwardButton_Tapped" Holding="BackwardButton_Holding"
               PointerExited="BackwardButton_PointerExited"/></StackPanel>



<TextBlock Name="txtBox1"  FontSize="18"
           HorizontalAlignment="Center" VerticalAlignment="Bottom"/>

C#

private static int i;
private void BackwardButton_Tapped(object sender, TappedRoutedEventArgs e)
{
    i++;

    txtBox1.Text = i.ToString();
}


private int a = 10;
private void BackwardButton_Holding(object sender, HoldingRoutedEventArgs e)
{
     BackwardButton.Content = "\xE100";
     try
     {
         a++;
         txtBox1.Text = a.ToString();
     }
     catch (Exception)
     {
         //Exception(ex);
     }
}



private void BackwardButton_PointerExited(object sender, PointerRoutedEventArgs e)
{           
    BackwardButton.Content = "\xE26C";            
}

Solutions i already tried- https://social.msdn.microsoft.com/Forums/en-US/e386e2e8-0312-4b1e-8eea-9522db83d632/click-and-tapped-event-should-not-fire-when-holding-event-perform?forum=wpdevelop

And solution tried on windows 8 but hold and tap event not available in UWP Click Event should not trigger when hold event perform

Shubham Sahu
  • 1,963
  • 1
  • 17
  • 34

1 Answers1

1

Note the Holding event will fire twice. First time is in HoldingState.Started state and second in HoldingState.Completed. All you have to do is wrap your logic within the following if statement

private void BackwardButton_Holding(object sender, HoldingRoutedEventArgs e)
{
    if (e.HoldingState == Windows.UI.Input.HoldingState.Started)
    {
        ...
    }

I'd recommend you to start using breakpoints to work out issues like this though. It should be fairly straight forward to figure out the Tapped event is never called during holding by putting a breakpoint at

txtBox1.Text = i.ToString();

Hope this helps.

Justin XL
  • 38,763
  • 7
  • 88
  • 133