简体   繁体   English

重置分接计数器WP8

[英]Reset tap Counter WP8

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. 我正在开发一个wp8应用程序,该应用程序需要多次点击才能进入另一页,但是我希望如果用户按下另一个按钮来重置计数器。 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. 我遇到的问题是,一旦轻按一个按钮,其他按钮的计数器也会上升,我什至制作了3个计数器,每个按钮一个,但是即使我按了一个按钮一次,按另一个按钮,计数器仍会上升一次并返回到第一个按下的按钮,计数器尚未重置。 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");

        }
    }

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. 并在您拥有的每个Click方法的开头调用它。

This will check if the sender is the same button as before, if not it reset the TapCount. 这将检查发件人是否与以前的按钮相同,否则将重置TapCount。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM