WaitForButtonPressAsync() private method

private WaitForButtonPressAsync ( ) : Task
return Task
Esempio 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();
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a InputDialog outside of the current window.
        /// </summary>
        /// <param name="window">The MetroWindow</param>
        /// <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 string ShowModalInputExternal(this MetroWindow window, string title, string message, MetroDialogSettings settings = null)
        {
            var win = CreateModalExternalWindow(window);

            settings = settings ?? window.MetroDialogOptions;

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

            SetDialogFontSizes(settings, dialog);

            win.Content = dialog;

            string result = null;

            dialog.WaitForButtonPressAsync().ContinueWith(task =>
            {
                result = task.Result;
                win.Invoke(win.Close);
            });

            HandleOverlayOnShow(settings, window);
            win.ShowDialog();
            HandleOverlayOnHide(settings, window);
            return(result);
        }
Esempio n. 3
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;

                    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());
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a InputDialog inside of the current window.
        /// </summary>
        /// <param name="window">The MetroWindow</param>
        /// <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
                    var dialog = new InputDialog(window, settings)
                    {
                        Title = title,
                        Message = message,
                        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(a =>
                            {
                                return ((Task)window.Dispatcher.Invoke(new Func <Task>(() =>
                                {
                                    window.SizeChanged -= sizeHandler;

                                    window.RemoveDialog(dialog);

                                    return HandleOverlayOnHide(settings, window);
                                }))).ContinueWith(y3 => y).Unwrap();
                            });
                        }).Unwrap();
                    }).Unwrap().Unwrap();
                }));
            }).Unwrap());
        }
Esempio n. 5
0
        public static Task <string> ShowInputAsync(this MetroWindow window, string title, string message, MetroDialogSettings settings = null)
        {
            Action action2 = null;
            Func <Task <string> > func7 = null;

            window.Dispatcher.VerifyAccess();
            return(DialogManager.HandleOverlayOnShow(settings, window).ContinueWith <Task <string> >((Task z) => {
                Dispatcher dispatcher1 = window.Dispatcher;
                Func <Task <string> > u003cu003e9_1 = func7;
                if (u003cu003e9_1 == null)
                {
                    Func <Task <string> > func3 = () => {
                        Func <Task <string>, Task <Task <string> > > func2 = null;
                        if (settings == null)
                        {
                            settings = window.MetroDialogOptions;
                        }
                        InputDialog inputDialog = new InputDialog(window, settings)
                        {
                            Title = title,
                            Message = message,
                            Input = settings.DefaultText,
                            SizeChangedHandler = DialogManager.SetupAndOpenDialog(window, inputDialog)
                        };
                        return inputDialog.WaitForLoadAsync().ContinueWith <Task <Task <string> > >((Task x) => {
                            if (DialogManager.DialogOpened != null)
                            {
                                Dispatcher dispatcher = window.Dispatcher;
                                Action u003cu003e9_3 = action2;
                                if (u003cu003e9_3 == null)
                                {
                                    Action action = () => DialogManager.DialogOpened(window, new DialogStateChangedEventArgs());
                                    Action action1 = action;
                                    action2 = action;
                                    u003cu003e9_3 = action1;
                                }
                                dispatcher.BeginInvoke(u003cu003e9_3, new object[0]);
                            }
                            Task <string> task = inputDialog.WaitForButtonPressAsync();
                            Func <Task <string>, Task <Task <string> > > u003cu003e9_4 = func2;
                            if (u003cu003e9_4 == null)
                            {
                                Func <Task <string>, Task <Task <string> > > func = (Task <string> y) => {
                                    Func <Task, Task <string> > func4 = null;
                                    this.dialog.OnClose();
                                    if (DialogManager.DialogClosed != null)
                                    {
                                        Dispatcher dispatcher1 = this.CS$ < > 8__locals1.window.Dispatcher;
                                        Action u003cu003e9_5 = this.CS$ < > 8__locals1.< > 9__5;
                                        if (u003cu003e9_5 == null)
                                        {
                                            DialogManager.< > c__DisplayClass1_0 cSu0024u003cu003e8_locals1 = this.CS$ < > 8__locals1;
                                            Action action = new Action(this.CS$ < > 8__locals1.< ShowInputAsync > b__5);
                                            Action action1 = action;
                                            cSu0024u003cu003e8_locals1.< > 9__5 = action;
                                            u003cu003e9_5 = action1;
                                        }
                                        dispatcher1.BeginInvoke(u003cu003e9_5, new object[0]);
                                    }
                                    Dispatcher dispatcher2 = this.CS$ < > 8__locals1.window.Dispatcher;
                                    Func <Task> u003cu003e9_6 = this.< > 9__6;
                                    if (u003cu003e9_6 == null)
                                    {
                                        Func <Task> func5 = () => this.dialog._WaitForCloseAsync();
                                        Func <Task> func6 = func5;
                                        this.< > 9__6 = func5;
                                        u003cu003e9_6 = func6;
                                    }
                                    return dispatcher2.Invoke <Task>(u003cu003e9_6).ContinueWith <Task <string> >((Task a) => {
                                        Dispatcher dispatcher = this.CS$ < > 8__locals1.window.Dispatcher;
                                        Func <Task> u003cu003e9_8 = this.< > 9__8;
                                        if (u003cu003e9_8 == null)
                                        {
                                            DialogManager.< > c__DisplayClass1_1 cSu0024u003cu003e8_locals2 = this;
                                            Func <Task> func = () => {
                                                this.CS$ < > 8__locals1.window.SizeChanged -= this.sizeHandler;
                                                this.CS$ < > 8__locals1.window.RemoveDialog(this.dialog);
                                                return DialogManager.HandleOverlayOnHide(this.CS$ < > 8__locals1.settings, this.CS$ < > 8__locals1.window);
                                            };
                                            Func <Task> func1 = func;
                                            cSu0024u003cu003e8_locals2.< > 9__8 = func;
                                            u003cu003e9_8 = func1;
                                        }
                                        Task task = dispatcher.Invoke <Task>(u003cu003e9_8);
                                        Func <Task, Task <string> > u003cu003e9_9 = func4;
                                        if (u003cu003e9_9 == null)
                                        {
                                            Func <Task, Task <string> > func2 = new Func <Task, Task <string> >(this.< ShowInputAsync > b__9);
                                            Func <Task, Task <string> > func3 = func2;
                                            func4 = func2;
                                            u003cu003e9_9 = func3;
                                        }
                                        return task.ContinueWith <Task <string> >(u003cu003e9_9).Unwrap <string>();
                                    });
                                };
                                Func <Task <string>, Task <Task <string> > > func1 = func;
                                func2 = func;
                                u003cu003e9_4 = func1;
                            }
                            return task.ContinueWith <Task <Task <string> > >(u003cu003e9_4).Unwrap <Task <string> >();
                        }).Unwrap <Task <string> >().Unwrap <string>();
                    };
                    Func <Task <string> > func4 = func3;
                    func7 = func3;
                    u003cu003e9_1 = func4;
                }
                return dispatcher1.Invoke <Task <string> >(u003cu003e9_1);
            }).Unwrap <string>());