Exemplo n.º 1
0
        /// <summary>
        /// Creates a child window CustomDialog on the given container.
        /// </summary>
        /// <param name="window">The window.</param>
        /// <param name="title">The title of the CustomDialog.</param>
        /// <param name="content">The data contained within the CustomDialog.</param>
        /// <param name="container">The container.</param>
        /// <param name="buttonPressCallbackAsync">A callback function to be executed when a button is pressed asynchronous.</param>
        /// <param name="style">The type of buttons to use.</param>
        /// <param name="settings">Optional Settings that override the global metro dialog settings.</param>
        /// <returns>A task promising the result of which button was pressed.</returns>
        public static Task <MessageDialogResult> ShowChildWindowCustomAsync(this Window window, string title, object content, Panel container, Func <MessageDialogResult, Task <bool> > buttonPressCallbackAsync, MessageDialogStyle style = MessageDialogStyle.Affirmative, ChildWindowDialogSettings settings = null)
        {
            var dialog = new CustomDialog(settings, buttonPressCallbackAsync)
            {
                Title         = title,
                DialogContent = content,
                ButtonStyle   = style
            };

            window.ShowChildWindowAsync <Task <MessageDialogResult> >(dialog, container);

            return(dialog.WaitForButtonPressAsync().ContinueWith(y =>
            {
                dialog.Dispatcher.Invoke(() => dialog.Close(y));

                return y;
            }).Unwrap());
        }
Exemplo n.º 2
0
        private static void SetButtonState(CustomDialog md)
        {
            if (md.PART_AffirmativeButton == null)
            {
                return;
            }

            switch (md.ButtonStyle)
            {
            case MessageDialogStyle.Affirmative:
            {
                md.PART_AffirmativeButton.Visibility     = Visibility.Visible;
                md.PART_NegativeButton.Visibility        = Visibility.Collapsed;
                md.PART_FirstAuxiliaryButton.Visibility  = Visibility.Collapsed;
                md.PART_SecondAuxiliaryButton.Visibility = Visibility.Collapsed;
            }
            break;

            case MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary:
            case MessageDialogStyle.AffirmativeAndNegativeAndDoubleAuxiliary:
            case MessageDialogStyle.AffirmativeAndNegative:
            {
                md.PART_AffirmativeButton.Visibility = Visibility.Visible;
                md.PART_NegativeButton.Visibility    = Visibility.Visible;

                if (md.ButtonStyle == MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary || md.ButtonStyle == MessageDialogStyle.AffirmativeAndNegativeAndDoubleAuxiliary)
                {
                    md.PART_FirstAuxiliaryButton.Visibility = Visibility.Visible;
                }

                if (md.ButtonStyle == MessageDialogStyle.AffirmativeAndNegativeAndDoubleAuxiliary)
                {
                    md.PART_SecondAuxiliaryButton.Visibility = Visibility.Visible;
                }
            }
            break;
            }

            md.AffirmativeButtonText     = md.DialogSettings.AffirmativeButtonText;
            md.NegativeButtonText        = md.DialogSettings.NegativeButtonText;
            md.FirstAuxiliaryButtonText  = md.DialogSettings.FirstAuxiliaryButtonText;
            md.SecondAuxiliaryButtonText = md.DialogSettings.SecondAuxiliaryButtonText;
        }