Beispiel #1
0
        public Task <bool> ShowAsync()
        {
            var dialogResult = new TaskCompletionSource <bool>();

            if (_config.IsDestructive)
            {
                AddAction(
                    AlertAction.Destructive(
                        _config.AcceptButtonText,
                        () => dialogResult.TrySetResult(true)));
            }
            else
            {
                AddAction(
                    AlertAction.Default(
                        _config.AcceptButtonText,
                        () => dialogResult.TrySetResult(true)));
            }

            if (_config.CancelButtonText != null)
            {
                AddAction(
                    AlertAction.Cancel(
                        _config.CancelButtonText,
                        () => dialogResult.TrySetResult(false)));
            }

            Present();

            return(dialogResult.Task);
        }
Beispiel #2
0
        public Task <object?> ShowAsync()
        {
            var dialogResult = new TaskCompletionSource <object?>();

            AddAction(
                AlertAction.Cancel(
                    _config.CloseButtonText,
                    () => dialogResult.TrySetResult(null)));

            Present();

            return(dialogResult.Task);
        }
Beispiel #3
0
        public Task <string> ShowAsync()
        {
            if (_config.OptionButtons == null)
            {
                throw new ArgumentNullException(nameof(_config.OptionButtons));
            }

            var dialogResult = new TaskCompletionSource <string>();

            if (_config.DestructButtonText != null)
            {
                AddAction(
                    AlertAction.Destructive(
                        _config.DestructButtonText,
                        () => dialogResult.TrySetResult(_config.DestructButtonText)));
            }

            foreach (var optionText in _config.OptionButtons)
            {
                AddAction(
                    AlertAction.Default(
                        optionText, () => dialogResult.TrySetResult(optionText)));
            }

            if (_config.CancelButtonText != null)
            {
                AddAction(
                    AlertAction.Cancel(
                        _config.CancelButtonText,
                        () => dialogResult.TrySetResult(_config.CancelButtonText)));
            }

            Present();

            return(dialogResult.Task);
        }
 protected virtual void AddAction(AlertAction alertAction)
 {
     Actions.Add(alertAction);
 }