using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//----------------------------------------------------------------
//Module Name: $safeprojectname$
//Purpose:
//CopyRight: Muchinfo
//History:
//----------------------------------------------------------------
//DateTime 2017/3/3 17:44:09
//Author
//Description Create
//----------------------------------------------------------------
using System.Threading;
using System.Windows.Threading;
using GalaSoft.MvvmLight;
using Muchinfo.MTPClient.Resources;
namespace Muchinfo.MTPClient.Bank.ViewModels
{
public class IdentifyCodeTimerViewModel:ViewModelBase
{
private const int c_tick = 60;
private DispatcherTimer indentifyCodeTimer;
private bool _isEnable=true;
///
/// 是否可以点验证码
///
public bool IsEnalbe
{
get { return _isEnable; }
set { Set(() => IsEnalbe, ref _isEnable, value); }
}
///
/// 当前倒数多少秒
///
public string CurrentTick
{
// get { return _currentTick; }
get
{
if (_curerntSconds <= 0)
{
return Client_Resource.Content_GetIdentifyCode;
}
return _curerntSconds + "s";
}
}
///
/// 当前秒数
///
private int _curerntSconds=0;
///
/// 当前秒数
///
public int CurerntSconds
{
get { return _curerntSconds; }
set
{
Set(() => CurerntSconds, ref _curerntSconds, value);
RaisePropertyChanged(() => CurrentTick);
}
}
public IdentifyCodeTimerViewModel()
{
indentifyCodeTimer=new DispatcherTimer();
indentifyCodeTimer.Interval =new TimeSpan(0,0,0, 1);
indentifyCodeTimer.Tick += indentifyCodeTimer_Tick;
}
void indentifyCodeTimer_Tick(object sender, EventArgs e)
{
CurerntSconds -= 1;
if (CurerntSconds <= 0)
{
indentifyCodeTimer.Stop();
IsEnalbe = true;
}
}
///
/// 启动计时
///
public void Start()
{
if (indentifyCodeTimer != null)
{
indentifyCodeTimer.Start();
CurerntSconds = c_tick;
IsEnalbe = false;
}
}
}
}