Question

I'm developing an wp8 Application that requires a number of taps to get to another page but I want the counter to reset if the user presses another button. here is my three buttons and the counter works fine i just want it to reset if another button is tapped. The problem I'm having is that once one button is tapped the other button counters go up as well and I even made 3 counters, one for each button and yet the counter still goes up even if i press one button once, press another button once and go back to the first button pressed the counter hasn't reset. Is there a way that if one button is pressed and another button is pressed that the first buttons counter will reset if another button is pressed. Thanks

    private void Instructions_Click(object sender, RoutedEventArgs e)
    {

            TapCount++;
        if (TapCount == 2)
        {
              NavigationService.Navigate(new Uri("/instructions.xaml", UriKind.Relative));

        }

        else
        {
            SayWords("You have selected the Instructions");

        }

    }


    private void Settings_Click(object sender, RoutedEventArgs e)
    {
        TapCount++;

        if (TapCount == 2)
        {
            NavigationService.Navigate(new Uri("/Settings.xaml", UriKind.Relative));
        }


        else
        {
            SayWords("You have selected the Settings");

        }
    }


    private void CreateMessage_Click(object sender, RoutedEventArgs e)
    {
        TapCount++;
        if (TapCount == 2)
        {
            NavigationService.Navigate(new Uri("/ctmessage.xaml", UriKind.Relative));
        }
        else
        {
            SayWords("You have selected the Create Message");

        }
    }
Was it helpful?

Solution

The problem here is that you are saying that you want the counter to be resetted but you're actually not doing it. Add this method to your class:

private object previousSender;
private void CheckSender(object sender)
{
    if (sender != previousSender)
    {
        TapCount = 0;
    }

    previousSender = sender;
}

and call it at the start of each Click method you have.

This will check if the sender is the same button as before, if not it reset the TapCount.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top