Exemplo n.º 1
0
        /// <summary>
        /// Creates a InputDialog inside of the current window.
        /// </summary>
        /// <param name="title">The title of the MessageDialog.</param>
        /// <param name="message">The message contained within the MessageDialog.</param>
        /// <param name="settings">Optional settings that override the global metro dialog settings.</param>
        /// <returns>The text that was entered or null (Nothing in Visual Basic) if the user cancelled the operation.</returns>
        public static Task<string> ShowInputAsync(this MetroWindow window, string title, string message, MetroDialogSettings settings = null)
        {
            window.Dispatcher.VerifyAccess();
            return HandleOverlayOnShow(settings, window).ContinueWith(z =>
                {
                    return (Task<string>)window.Dispatcher.Invoke(new Func<Task<string>>(() =>
                        {
                            if (settings == null)
                                settings = window.MetroDialogOptions;

                            //create the dialog control
                            InputDialog dialog = new InputDialog(window, settings);
                            dialog.Title = title;
                            dialog.Message = message;
                            dialog.Input = settings.DefaultText;

                            SizeChangedEventHandler sizeHandler = SetupAndOpenDialog(window, dialog);
                            dialog.SizeChangedHandler = sizeHandler;

                            return dialog.WaitForLoadAsync().ContinueWith(x =>
                            {
                                if (DialogOpened != null)
                                {
                                    window.Dispatcher.BeginInvoke(new Action(() => DialogOpened(window, new DialogStateChangedEventArgs()
                                    {
                                    })));
                                }

                                return dialog.WaitForButtonPressAsync().ContinueWith(y =>
                                {
                                    //once a button as been clicked, begin removing the dialog.

                                    dialog.OnClose();

                                    if (DialogClosed != null)
                                    {
                                        window.Dispatcher.BeginInvoke(new Action(() => DialogClosed(window, new DialogStateChangedEventArgs()
                                        {
                                        })));
                                    }

                                    Task closingTask = (Task)window.Dispatcher.Invoke(new Func<Task>(() => dialog._WaitForCloseAsync()));
                                    return closingTask.ContinueWith<Task<string>>(a =>
                                        {
                                            return ((Task)window.Dispatcher.Invoke(new Func<Task>(() =>
                                            {
                                                window.SizeChanged -= sizeHandler;

                                                window.metroDialogContainer.Children.Remove(dialog); //remove the dialog from the container

                                                return HandleOverlayOnHide(settings, window);
                                                //window.overlayBox.Visibility = System.Windows.Visibility.Hidden; //deactive the overlay effect

                                            }))).ContinueWith(y3 => y).Unwrap();
                                        });
                                }).Unwrap();
                            }).Unwrap().Unwrap();
                        }));
                }).Unwrap();
        }
Exemplo n.º 2
0
        //private const string PART_AffirmativeButton = "PART_AffirmativeButton";
        //private const string PART_NegativeButton = "PART_NegativeButton";

        //private Button AffirmativeButton = null;
        //private Button NegativeButton = null;

        //static MessageDialog()
        //{
        //    //DefaultStyleKeyProperty.OverrideMetadata(typeof(MessageDialog), new FrameworkPropertyMetadata(typeof(MessageDialog)));
        //}
        internal ProgressDialog(MetroWindow parentWindow, MetroDialogSettings settings)
            : base(parentWindow, settings)
        {
            InitializeComponent();

            if (parentWindow.MetroDialogOptions.ColorScheme == MetroDialogColorScheme.Theme)
            {
                try
                {
                    ProgressBarForeground = ThemeManager.GetResourceFromAppStyle(parentWindow, "AccentColorBrush") as Brush;
                }
                catch (Exception) { }
            }
            else
                ProgressBarForeground = Brushes.White;
        }
Exemplo n.º 3
0
        private async void ShowMessageDialog(object sender, RoutedEventArgs e)
        {
            // This demo runs on .Net 4.0, but we're using the Microsoft.Bcl.Async package so we have async/await support
            // The package is only used by the demo and not a dependency of the library!
            MetroDialogOptions.ColorScheme = UseAccentForDialogsMenuItem.IsChecked ? MetroDialogColorScheme.Accented : MetroDialogColorScheme.Theme;

            var mySettings = new MetroDialogSettings()
            {
                AffirmativeButtonText = "Hi",
                NegativeButtonText = "Go away!",
                FirstAuxiliaryButtonText = "Cancel",
                ColorScheme = UseAccentForDialogsMenuItem.IsChecked ? MetroDialogColorScheme.Accented : MetroDialogColorScheme.Theme
            };

            MessageDialogResult result = await this.ShowMessageAsync("Hello!", "Welcome to the world of metro! ",
                MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary, mySettings);

            if (result != MessageDialogResult.FirstAuxiliary)
                await this.ShowMessageAsync("Result", "You said: " + (result == MessageDialogResult.Affirmative ? mySettings.AffirmativeButtonText : mySettings.NegativeButtonText +
                    Environment.NewLine + Environment.NewLine + "This dialog will follow the Use Accent setting."));
        }
Exemplo n.º 4
0
        private async void MetroWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = !_shutdown && _viewModel.QuitConfirmationEnabled;
            if (_shutdown) return;

            var mySettings = new MetroDialogSettings()
            {
                AffirmativeButtonText = "Quit",
                NegativeButtonText = "Cancel",
                AnimateShow = true,
                AnimateHide = false
            };

            var result = await this.ShowMessageAsync("Quit application?",
                "Sure you want to quit application?",
                MessageDialogStyle.AffirmativeAndNegative, mySettings);

            _shutdown = result == MessageDialogResult.Affirmative;

            if (_shutdown)
                Application.Current.Shutdown();
        }
Exemplo n.º 5
0
 private static Task HandleOverlayOnShow(MetroDialogSettings settings, MetroWindow window)
 {
     return (settings == null || settings.AnimateShow ? window.ShowOverlayAsync() : Task.Factory.StartNew(() => window.Dispatcher.Invoke(new Action(() => window.ShowOverlay()))));
 }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a ProgressDialog inside of the current window.
        /// </summary>
        /// <param name="title">The title of the ProgressDialog.</param>
        /// <param name="message">The message within the ProgressDialog.</param>
        /// <param name="isCancelable">Determines if the cancel button is visible.</param>
        /// <param name="settings">Optional Settings that override the global metro dialog settings.</param>
        /// <returns>A task promising the instance of ProgressDialogController for this operation.</returns>
        public static Task<ProgressDialogController> ShowProgressAsync(this MetroWindow window, string title, string message, bool isCancelable = false, MetroDialogSettings settings = null)
        {
            window.Dispatcher.VerifyAccess();

            return HandleOverlayOnShow(settings, window).ContinueWith(z =>
            {
                return ((Task<ProgressDialogController>)window.Dispatcher.Invoke(new Func<Task<ProgressDialogController>>(() =>
                    {
                        //create the dialog control
                        ProgressDialog dialog = new ProgressDialog(window);
                        dialog.Message = message;
                        dialog.Title = title;
                        dialog.IsCancelable = isCancelable;

                        if (settings == null)
                            settings = window.MetroDialogOptions;

                        dialog.NegativeButtonText = settings.NegativeButtonText;

                        SizeChangedEventHandler sizeHandler = SetupAndOpenDialog(window, dialog);
                        dialog.SizeChangedHandler = sizeHandler;

                        return dialog.WaitForLoadAsync().ContinueWith(x =>
                        {
                            if (DialogOpened != null)
                            {
                                window.Dispatcher.BeginInvoke(new Action(() => DialogOpened(window, new DialogStateChangedEventArgs()
                                {
                                })));
                            }

                            return new ProgressDialogController(dialog, () =>
                            {
                                dialog.OnClose();

                                if (DialogClosed != null)
                                {
                                    window.Dispatcher.BeginInvoke(new Action(() => DialogClosed(window, new DialogStateChangedEventArgs()
                                    {
                                    })));
                                }

                                Task closingTask = (Task)window.Dispatcher.Invoke(new Func<Task>(() => dialog._WaitForCloseAsync()));
                                return closingTask.ContinueWith<Task>(a =>
                                {
                                    return (Task)window.Dispatcher.Invoke(new Func<Task>(() =>
                                    {
                                        window.SizeChanged -= sizeHandler;

                                        window.metroDialogContainer.Children.Remove(dialog); //remove the dialog from the container

                                        return HandleOverlayOnHide(settings, window);
                                        //window.overlayBox.Visibility = System.Windows.Visibility.Hidden; //deactive the overlay effect
                                    }));
                                }).Unwrap();
                            });
                        });
                    })));
            }).Unwrap();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initializes a new MVVMApps.Metro.Controls.BaseMetroDialog.
        /// </summary>
        protected BaseMetroDialog()
        {
            DialogSettings = new MetroDialogSettings();

            Initialize();
        }
Exemplo n.º 8
0
        /// <summary>
        /// Initializes a new MVVMApps.Metro.Controls.BaseMetroDialog.
        /// </summary>
        /// <param name="owningWindow">The window that is the parent of the dialog.</param>
        protected BaseMetroDialog(MetroWindow owningWindow, MetroDialogSettings settings)
        {
            DialogSettings = settings ?? owningWindow.MetroDialogOptions;

            OwningWindow = owningWindow;
            
            Initialize();
        }