using Avalonia.Controls; using ReactiveUI; using System.Threading; namespace Captchapp.ViewModels { public class MainWindowViewModel : ViewModelBase { UserControl control = new Page1(); public UserControl Control { get => control; set => this.RaiseAndSetIfChanged(ref control, value); } Page1ViewModel page1VM = new Page1ViewModel(); Page2ViewModel page2VM = new Page2ViewModel(); public Page1ViewModel Page1VM { get => page1VM; set => page1VM = value; } public Page2ViewModel Page2VM { get => page2VM; set => page2VM = value; } public void toPage1() { Control = new Page1(); } public void toPage2() { if (Page1VM.Authorize()) { Control = new Page2(); Page1VM.ErrorMessage = ""; Page1VM.ErrorVisibility = false; } else { Page1VM.ErrorMessage = "Логин или пароль неправильные. Повторите попытку"; Page1VM.ErrorVisibility = true; Page1VM.makeCaptcha(); Page1VM.LoginVisibility = false; } } private Timer timer; private int count = 0; public void toPage2Captcha() { if (Page1VM.checkCaptcha()) { Page1VM.ErrorVisibility = false; Page1VM.LoginVisibility = true; Page1VM.CaptchaVisibility = false; Control = new Page2(); Page1VM.ErrorMessage = ""; } else { Page1VM.ErrorMessage = "Логин или пароль неправильные. Повторите попытку"; Page1VM.ErrorVisibility = true; Page1VM.makeCaptcha(); Page1VM.CaptchaVisibility = false; Page1VM.LoginVisibility = false; // Здесь вызывается таймер Page1VM.TimerVisibility = true; Page1VM.TextBoxEnable = false; Page1VM.Password = ""; Page1VM.Email = ""; timer = new Timer(timerText, null, 0,1000); } } public void timerText(object? obj) { count++; Page1VM.TimerMessage = $"Попробуйте снова через {10-count} секунд"; if (count >= 10) { Page1VM.TimerVisibility = false; Page1VM.TextBoxEnable = true; Page1VM.CaptchaVisibility = true; count = 0; timer.Dispose(); } } } }