UWP 發送短信公用倒計時按鈕

1.要求:
     發送驗證碼按鈕,點擊後,會倒計時60s,以後才能再次點擊。不一樣界面的多個驗證碼按鈕共享這個倒計時時間。
2.操做步驟
      1) 從登陸界面-->忘記密碼輸入手機號-->下一步-->倒計時60s
      2) 返回到註冊頁面-->輸入手機號碼-->下一步-->獲取計時器倒計時到48s,而後從48s繼續倒計時
      3) 登陸到我的中心-->帳戶安全-->修改登陸密碼-->獲取計時器倒計時35s,而後從35s繼續倒計時
      4) 返回到我的中心-->帳戶安全-->修改支付密碼-->獲取計時器倒計時25s,而後從25s繼續倒計時
3.我寫了個公用的方法以下:
 1     /// <summary>
 2     /// 倒計時類(發送驗證碼按鈕,點擊後,會倒計時60s,以後才能再次點擊。不一樣界面的多個驗證碼按鈕共享這個倒計時時間。)同一手機號碼1分鐘只能發1條;
 3     /// </summary>
 4     public static class CountDown
 5     {
 6         /// <summary>
 7         /// 倒計時60秒
 8         /// </summary>
 9         public static int stTimeCount = 0;
10       
11         /// <summary>
12         /// 倒計時60s方法
13         /// </summary>
14         /// <param name="btnCode"></param>
15         /// <param name="timeCount"></param>
16         public static void ShowCountDown(Button btnCode, int timeCount)
17         {
18             stTimeCount = timeCount;
19             DispatcherTimer dispatcherTimer = new DispatcherTimer();
20             dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
21             dispatcherTimer.Start();
22             int count = stTimeCount;
23             int i = 0;
24             dispatcherTimer.Tick += delegate
25             {
26                 if (count > 0)
27                     count--;
28                 //倒計時:設置按鈕的值,以及按鈕不可點擊
29                 btnCode.Content = count + " S ";
30                 btnCode.IsEnabled = false;
31                 stTimeCount = count;
32                 if (count == i)
33                 {
34                     //倒計時完成: 設置按鈕的值,以及按鈕可用
35                     dispatcherTimer.Stop();
36                     btnCode.Content = "獲取驗證碼";
37                     btnCode.IsEnabled = true;
38                     stTimeCount = count ;
39                 }
40             };
41         }
42     }

4.修改登陸密碼界面構造函數中進行調用安全

 1     public SetLoginPwd()
 2         {
 3             this.InitializeComponent();
 4 
 5             //獲取倒計時60秒是否有值,有值則繼續倒計時
 6             if (CountDown.stTimeCount > 0)
 7             {
 8                 CountDown.ShowCountDown(btnCode, CountDown.stTimeCount);
 9             }
10         }
相關文章
相關標籤/搜索