Windows Phone事件第二次没有触发

时间:2014-09-03 14:40:54

标签: c# events windows-phone-8

我尝试第二次发射事件时遇到问题。下面的示例代码向用户显示登录页面,并在完成时触发事件。如果用户登录失败或拒绝,则会向他们发出警告,并询问他们是否愿意再次尝试。如果他们接受并登录或不登出第二个事件?

我试过了:

    ShowLogon(new EventHandler(ourEvent);

还将warn用户方法定义为:

    private void warnUser(Object sender)

并将事件定义如下,但在两种情况下,登录失败时的第二个事件都不会触发player_loginCompleted方法,为什么?

    EventHandler ourEvent = new EventHandler(player_LogonCompleted);

    private void chronoButton_Click(object sender, RoutedEventArgs e)
    {
       ShowLogon(ourEvent);   <--- shows login page and fires event
    }

    void player_LogonCompleted(object sender, EventArgs e)
    {
       if(playerLoggedIn)
       {
            starGame();
       }
       else
       {
             warnUser();
       }
    }

    void warnUser()
    {
           // login failed or user cancelled so warn them and ask them if they would like to sign up/in
        if (MessageBox.Show("Center, Leaderboards, Achievements and announcements will not be awarded if your not logged in!",
                    "Would you like to log in now?", MessageBoxButton.OKCancel) != MessageBoxResult.OK)
        {
            // User declined to sign up
            Debug.WriteLine("Player declined to login");
        }
        else
        {
            Debug.WriteLine("Player accepted to login");
            // Show Center sign up page
            ShowLogon(ourEvent);  <--- here showing login page but not firing the event again
        }
     }

非常感谢

0 个答案:

没有答案