MahApps.Metro.Controls.Dialogs.ProgressDialogController.CloseAsync C# (CSharp) Method

CloseAsync() public method

Begins an operation to close the ProgressDialog.
public CloseAsync ( ) : System.Threading.Tasks.Task
return System.Threading.Tasks.Task
        public Task CloseAsync()
        {
            Action action = () =>
                {
                    if (!this.WrappedDialog.IsVisible)
                    {
                        throw new InvalidOperationException("Dialog isn't visible to close");
                    }
                    this.WrappedDialog.Dispatcher.VerifyAccess();
                    this.WrappedDialog.PART_NegativeButton.Click -= this.PART_NegativeButton_Click;
                };

            this.WrappedDialog.Invoke(action);

            return this.CloseCallback()
                       .ContinueWith(_ => this.WrappedDialog.Invoke(() =>
                                                                        {
                                                                            this.IsOpen = false;
                                                                            this.Closed?.Invoke(this, EventArgs.Empty);
                                                                        }));
        }
    }

Usage Example

Esempio n. 1
0
        private async void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            var email = txtEMail.Text;
            var pwd = txtPwd.Password;

            if (string.IsNullOrEmpty(email) && string.IsNullOrEmpty(pwd))
            {
                txtError.Text = "Please enter a EMail and a Password!";
                return;
            }
            else if (string.IsNullOrEmpty(pwd))
            {
                txtError.Text = "Please enter a Password";
                return;
            }
            else if (string.IsNullOrEmpty(email))
            {
                txtError.Text = "Please enter a EMail";
                return;
            }
            txtError.Text = "";

            IsEnabled = false;
            _controller = await this.ShowProgressAsync("Logging in...", "Authenticating...");
            _controller.SetIndeterminate();

            var result = await Task.Factory.StartNew(() =>
            {
                return commander.AuthenticateUser(email, pwd);
            });

            txtPwd.Password = "";

            await _controller.CloseAsync();

            IsEnabled = true;
            if (result == true)
            {
                await this.ShowMessageAsync("Authenticated", "Login success!");
                MainWindow mainWindow = new MainWindow();
                mainWindow.Show();
                Close();
            }
            else
            {
                txtError.Text = "Combination of EMail and Password is incorrect!";
            }
            _controller.SetProgress(1);
        }
All Usage Examples Of MahApps.Metro.Controls.Dialogs.ProgressDialogController::CloseAsync