Exemplo n.º 1
0
        /// <summary>
        /// show a confirm dialog like MessageBox of Windows
        /// </summary>
        /// <param name="content">the content of dialog</param>
        /// <param name="title">the title of dialog</param>
        /// <param name="confirmButtons">the buttons of dialog</param>
        /// <param name="confirmIcon">the icon of dialog</param>
        /// <param name="options">the configuration options for dialog</param>
        /// <param name="autoFocusButton">the autofocus button</param>
        /// <returns></returns>
        public async Task <ConfirmResult> Show(
            OneOf <string, RenderFragment> content,
            OneOf <string, RenderFragment> title,
            ConfirmButtons confirmButtons,
            ConfirmIcon confirmIcon,
            ConfirmButtonOptions options,
            ConfirmAutoFocusButton?autoFocusButton = ConfirmAutoFocusButton.Ok)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            ConfirmOptions confirmOptions = new ConfirmOptions()
            {
                Content        = content,
                ConfirmButtons = confirmButtons,
                ConfirmIcon    = confirmIcon,
            };

            if (autoFocusButton != null)
            {
                confirmOptions.AutoFocusButton = (ConfirmAutoFocusButton)autoFocusButton;
            }

            if (title.IsT0)
            {
                confirmOptions.Title = title.AsT0;
            }
            else
            {
                confirmOptions.TitleTemplate = title.AsT1;
            }

            #region config button default properties

            if (options.Button1Props != null)
            {
                confirmOptions.Button1Props = options.Button1Props;
            }
            if (options.Button2Props != null)
            {
                confirmOptions.Button2Props = options.Button2Props;
            }
            if (options.Button3Props != null)
            {
                confirmOptions.Button3Props = options.Button3Props;
            }

            #endregion

            var confirmRef = new ConfirmRef(confirmOptions)
            {
                TaskCompletionSource = new TaskCompletionSource <ConfirmResult>()
            };
            if (OnOpenEvent != null)
            {
                await OnOpenEvent.Invoke(confirmRef);
            }
            return(await confirmRef.TaskCompletionSource.Task);
        }
Exemplo n.º 2
0
 /// <summary>
 /// show a confirm dialog like MessageBox of Windows
 /// </summary>
 /// <param name="content">the content of dialog</param>
 /// <param name="title">the title of dialog</param>
 /// <param name="confirmButtons">the buttons of dialog</param>
 /// <param name="confirmIcon">the icon of dialog</param>
 /// <returns></returns>
 public Task <ConfirmResult> Show
     (OneOf <string, RenderFragment> content,
     OneOf <string, RenderFragment> title,
     ConfirmButtons confirmButtons = ConfirmButtons.OKCancel,
     ConfirmIcon confirmIcon       = ConfirmIcon.Info)
 {
     return(Show(content, title, confirmButtons, confirmIcon, new ConfirmButtonOptions()));
 }
Exemplo n.º 3
0
        /// <summary>
        /// show a confirm dialog like MessageBox of Windows
        /// </summary>
        /// <param name="content">the content of dialog</param>
        /// <param name="title">the title of dialog</param>
        /// <param name="confirmButtons">the buttons of dialog</param>
        /// <param name="confirmIcon">the icon of dialog</param>
        /// <param name="options">the configuration options for dialog</param>
        /// <returns></returns>
        public async Task <ConfirmResult> Show(
            OneOf <string, RenderFragment> content,
            OneOf <string, RenderFragment> title,
            ConfirmButtons confirmButtons,
            ConfirmIcon confirmIcon,
            ConfirmButtonOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            ConfirmOptions confirmOptions = new ConfirmOptions()
            {
                Title          = title,
                Content        = content,
                ConfirmButtons = confirmButtons,
                ConfirmIcon    = confirmIcon,
            };

            #region config button default properties

            if (options.Button1Props != null)
            {
                confirmOptions.Button1Props = options.Button1Props;
            }
            if (options.Button2Props != null)
            {
                confirmOptions.Button2Props = options.Button2Props;
            }
            if (options.Button3Props != null)
            {
                confirmOptions.Button3Props = options.Button3Props;
            }

            #endregion

            var modalRef = new ConfirmRef(confirmOptions)
            {
                TaskCompletionSource = new TaskCompletionSource <ConfirmResult>()
            };
            if (OnOpenEvent != null)
            {
                await OnOpenEvent.Invoke(modalRef);
            }
            return(await modalRef.TaskCompletionSource.Task);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="caption">The caption</param>
        /// <param name="description">The description</param>
        /// <param name="buttonSelection">The default button selection</param>
        public MessageBoxViewModel(string caption, string description, MessageBoxButtons buttonSelection = MessageBoxButtons.OK | MessageBoxButtons.Cancel)
            : base(typeof(MessageBoxViewModel))
        {
            _toggleButtons  = new List <MessageBoxButton>();
            _confirmButtons = new List <MessageBoxButton>();
            _optionButtons  = new List <MessageBoxButton>();

            ButtonClickedCommand = new RelayCommand((o) => ButtonClicked(o as MessageBoxButton), (o) => CanButtonBeClicked(o as MessageBoxButton));

            if (buttonSelection.HasFlag(MessageBoxButtons.OK))
            {
                ConfirmButtons.Add(new MessageBoxButton("OK"));
            }
            if (buttonSelection.HasFlag(MessageBoxButtons.Later))
            {
                ConfirmButtons.Add(new MessageBoxButton("Not now"));
            }
            if (buttonSelection.HasFlag(MessageBoxButtons.Cancel))
            {
                ConfirmButtons.Add(new MessageBoxButton("Cancel"));
            }

            if (ConfirmButtons.Any())
            {
                if (!ConfirmButtons.Any(button => button.IsDefault))
                {
                    ConfirmButtons.First().IsDefault = true;
                }
                if (!ConfirmButtons.Any(button => button.IsCancel))
                {
                    ConfirmButtons.Last().IsCancel = true;
                }
            }

            Caption     = caption;
            Description = description;
        }