WaitForLoadAsync() публичный Метод

Waits for the dialog to become ready for interaction.
public WaitForLoadAsync ( ) : System.Threading.Tasks.Task
Результат System.Threading.Tasks.Task
Пример #1
0
        /// <summary>
        /// Adds a Metro Dialog instance to the specified window and makes it visible.
        /// <para>Note that this method returns as soon as the dialog is loaded and won't wait on a call of <see cref="HideMetroDialogAsync"/>.</para>
        /// <para>You can still close the resulting dialog with <see cref="HideMetroDialogAsync"/>.</para>
        /// </summary>
        /// <param name="window">The owning window of the dialog.</param>
        /// <param name="dialog">The dialog instance itself.</param>
        /// <returns>A task representing the operation.</returns>
        /// <exception cref="InvalidOperationException">The <paramref name="dialog"/> is already visible in the window.</exception>
        public static Task ShowMetroDialogAsync(this MetroWindow window, BaseMetroDialog dialog)
        {
            window.Dispatcher.VerifyAccess();
            if (window.metroDialogContainer.Children.Contains(dialog))
            {
                throw new InvalidOperationException("The provided dialog is already visible in the specified window.");
            }

            return(window.ShowOverlayAsync().ContinueWith(z =>
            {
                dialog.Dispatcher.Invoke(new Action(() =>
                {
                    SizeChangedEventHandler sizeHandler = SetupAndOpenDialog(window, dialog);
                    dialog.SizeChangedHandler = sizeHandler;
                }));
            }).ContinueWith(y =>
                            ((Task)dialog.Dispatcher.Invoke(new Func <Task>(() => dialog.WaitForLoadAsync().ContinueWith(x =>
            {
                dialog.OnShown();

                if (DialogOpened != null)
                {
                    DialogOpened(window, new DialogStateChangedEventArgs()
                    {
                    });
                }
            }))))));
        }
Пример #2
0
        /// <summary>
        /// Adds a Metro Dialog instance to the specified window and makes it visible asynchronously.
        /// If you want to wait until the user has closed the dialog, use <see cref="ShowMetroDialogAsyncAwaitable"/>
        /// <para>You have to close the resulting dialog yourself with <see cref="HideMetroDialogAsync"/>.</para>
        /// </summary>
        /// <param name="window">The owning window of the dialog.</param>
        /// <param name="dialog">The dialog instance itself.</param>
        /// <param name="settings">An optional pre-defined settings instance.</param>
        /// <returns>A task representing the operation.</returns>
        /// <exception cref="InvalidOperationException">The <paramref name="dialog"/> is already visible in the window.</exception>
        public static Task ShowMetroDialogAsync(this MetroWindow window, BaseMetroDialog dialog,
                                                MetroDialogSettings settings = null)
        {
            window.Dispatcher.VerifyAccess();
            if (window.metroActiveDialogContainer.Children.Contains(dialog) || window.metroInactiveDialogContainer.Children.Contains(dialog))
            {
                throw new InvalidOperationException("The provided dialog is already visible in the specified window.");
            }

            return(HandleOverlayOnShow(settings, window).ContinueWith(z =>
            {
                return (Task)window.Dispatcher.Invoke(new Func <Task>(() =>
                {
                    settings = settings ?? window.MetroDialogOptions;

                    SetDialogFontSizes(settings, dialog);

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

                    return dialog.WaitForLoadAsync().ContinueWith(x =>
                    {
                        dialog.OnShown();

                        if (DialogOpened != null)
                        {
                            window.Dispatcher.BeginInvoke(new Action(() => DialogOpened(window, new DialogStateChangedEventArgs())));
                        }
                    });
                }));
            }).Unwrap());
        }
Пример #3
0
        public static Task <object> ShowBaseMetroDialog(this MetroWindow window, BaseMetroDialog dialog)
        {
            window.Dispatcher.VerifyAccess();
            return(HandleOverlayOnShow(null, window).ContinueWith(z =>
            {
                return (Task <object>)window.Dispatcher.Invoke(new Func <Task <object> >(() =>
                {
                    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(null, window);
                                }))).ContinueWith(y3 => y).Unwrap();
                            });
                        }).Unwrap();
                    }).Unwrap().Unwrap();
                }));
            }).Unwrap());
        }
        /// <summary>
        /// Adds a Metro Dialog instance to the specified window and makes it visible.
        /// </summary>
        /// <param name="window">The owning window of the dialog.</param>
        /// <param name="title">The title to be set in the dialog.</param>
        /// <param name="dialog">The dialog instance itself.</param>
        /// <returns>A task representing the operation.</returns>
        public static Task ShowMetroDialogAsync(this MetroWindow window, string title, BaseMetroDialog dialog)
        {
            window.Dispatcher.VerifyAccess();
            if (window.messageDialogContainer.Children.Contains(dialog))
                throw new Exception("The provided dialog is already visible in the specified window.");

            return window.ShowOverlayAsync().ContinueWith(z =>
                {
                    dialog.Dispatcher.Invoke(new Action(() =>
                        {
                            SizeChangedEventHandler sizeHandler = SetupAndOpenDialog(window, title, dialog);
                            dialog.SizeChangedHandler = sizeHandler;
                        }));
                }).ContinueWith(y =>
                    ((Task)dialog.Dispatcher.Invoke(new Func<Task>(() => dialog.WaitForLoadAsync())))).Unwrap();
        }
Пример #5
0
        /// <summary>
        /// Adds a Metro Dialog instance to the specified window and makes it visible.
        /// </summary>
        /// <param name="window">The owning window of the dialog.</param>
        /// <param name="title">The title to be set in the dialog.</param>
        /// <param name="dialog">The dialog instance itself.</param>
        /// <returns>A task representing the operation.</returns>
        /// <exception cref="InvalidOperationException">The <paramref name="dialog"/> is already visible in the window.</exception>
        public static Task ShowMetroDialogAsync(this MetroWindow window, BaseMetroDialog dialog)
        {
            window.Dispatcher.VerifyAccess();
            if (window.metroDialogContainer.Children.Contains(dialog))
                throw new InvalidOperationException("The provided dialog is already visible in the specified window.");

            return window.ShowOverlayAsync().ContinueWith(z =>
                {
                    dialog.Dispatcher.Invoke(new Action(() =>
                        {
                            SizeChangedEventHandler sizeHandler = SetupAndOpenDialog(window, dialog);
                            dialog.SizeChangedHandler = sizeHandler;
                        }));
                }).ContinueWith(y =>
                    ((Task)dialog.Dispatcher.Invoke(new Func<Task>(() => dialog.WaitForLoadAsync().ContinueWith(x =>
                        {
                            dialog.OnShown();

                            if (DialogOpened != null)
                            {
                                DialogOpened(window, new DialogStateChangedEventArgs()
                                {
                                });
                            }
                        })))));
        }