locked
Appbar button counter RRS feed

  • Question

  • Hi,

    I've implemented an appbar in each flipview which consists of a start and stop button. 

    What I want to do is that when the start button of an item is clicked for the very first time, 2 await methods are called. And if it is clicked for the second time onwards, it only calls 1 of the await method.

    For example, if I select an item and click the start button, the 2 await buttons are called successfully. However, when I navigate to the next item in the flipview or any other item, and click the start button, it is considered as a second click onwards despite me clicking a different item. 

    Thus, how can I implement it in such a way that the click count only applies to each individual item instead of the click count applies to all items as a whole?

    Thanks. 

    Regards,

    Eka

    Tuesday, August 27, 2013 4:31 AM

Answers

  • Use a global boolean which all of the buttons set to true once when they are clicked. EX:

    public Boolean RunSecondAwaitMethod = true;
    
    private async void Button_Click_1(object sender, RoutedEventArgs e)
    {
      await AwaitableMethod();
      if (RunSecondAwaitMethod) await AwaitableMethod2();
      RunSecondAwaitMethod = false;
    }
    
    private void Button_Click_2(object sender, RoutedEventArgs e)
    {
      await AwaitableMethod();
      if (RunSecondAwaitMethod) await AwaitableMethod2();
      RunSecondAwaitMethod = false;
    }
    
    private async Task<object> AwaitableMethod()
    {
      // Do something           
    }
    
    private async Task<object> AwaitableMethod2()
    {
      // Do something           
    }



    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by Anne Jing Friday, August 30, 2013 1:36 PM
    Tuesday, August 27, 2013 1:05 PM
    Moderator