/// <summary> /// Hides a visible Metro Dialog instance. /// </summary> /// <param name="window">The window with the dialog that is visible.</param> /// <param name="dialog">The dialog instance to hide.</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 not visible in the window. /// This happens if <see cref="ShowMetroDialogAsync"/> hasn't been called before. /// </exception> public static Task HideMetroDialogAsync(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 not visible in the specified window."); } window.SizeChanged -= dialog.SizeChangedHandler; dialog.OnClose(); Task closingTask = (Task)window.Dispatcher.Invoke(new Func <Task>(dialog.WaitForCloseAsync)); return(closingTask.ContinueWith(a => { if (DialogClosed != null) { window.Dispatcher.BeginInvoke(new Action(() => DialogClosed(window, new DialogStateChangedEventArgs()))); } return (Task)window.Dispatcher.Invoke(new Func <Task>(() => { window.RemoveDialog(dialog); settings = settings ?? (dialog.DialogSettings ?? window.MetroDialogOptions); return HandleOverlayOnHide(settings, window); })); }).Unwrap()); }
/// <summary> /// Hides a visible Metro Dialog instance. /// </summary> /// <param name="window">The window with the dialog that is visible.</param> /// <param name="dialog">The dialog instance to hide.</param> /// <returns>A task representing the operation.</returns> /// <exception cref="InvalidOperationException"> /// The <paramref name="dialog"/> is not visible in the window. /// This happens if <see cref="ShowMetroDialogAsync"/> hasn't been called before. /// </exception> public static Task HideMetroDialogAsync(this MetroWindow window, BaseMetroDialog dialog) { window.Dispatcher.VerifyAccess(); if (!window.metroDialogContainer.Children.Contains(dialog)) { throw new InvalidOperationException("The provided dialog is not visible in the specified window."); } window.SizeChanged -= dialog.SizeChangedHandler; dialog.OnClose(); Task closingTask = (Task)window.Dispatcher.Invoke(new Func <Task>(() => dialog._WaitForCloseAsync())); return(closingTask.ContinueWith <Task>(a => { if (DialogClosed != null) { window.Dispatcher.BeginInvoke(new Action(() => DialogClosed(window, new DialogStateChangedEventArgs() { }))); } return (Task)window.Dispatcher.Invoke(new Func <Task>(() => { window.metroDialogContainer.Children.Remove(dialog); //remove the dialog from the container return window.HideOverlayAsync(); })); }).Unwrap()); }
/// <summary> /// Hides a visible Metro Dialog instance. /// </summary> /// <param name="window">The window with the dialog that is visible.</param> /// <param name="dialog">The dialog instance to hide.</param> /// <returns>A task representing the operation.</returns> /// <exception cref="InvalidOperationException"> /// The <paramref name="dialog"/> is not visible in the window. /// This happens if <see cref="ShowMetroDialogAsync"/> hasn't been called before. /// </exception> public static Task HideMetroDialogAsync(this MetroWindow window, BaseMetroDialog dialog, MetroDialogSettings settings = null) { window.Dispatcher.VerifyAccess(); if (!window.metroDialogContainer.Children.Contains(dialog)) throw new InvalidOperationException("The provided dialog is not visible in the specified window."); window.SizeChanged -= dialog.SizeChangedHandler; dialog.OnClose(); Task closingTask = (Task)window.Dispatcher.Invoke(new Func<Task>(dialog._WaitForCloseAsync)); return closingTask.ContinueWith(a => { if (DialogClosed != null) { window.Dispatcher.BeginInvoke(new Action(() => DialogClosed(window, new DialogStateChangedEventArgs()))); } return (Task)window.Dispatcher.Invoke(new Func<Task>(() => { window.metroDialogContainer.Children.Remove(dialog); //remove the dialog from the container return HandleOverlayOnHide(settings, window); })); }).Unwrap(); }
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()); }
public static Task HideMetroDialogAsync(this MetroWindow window, BaseMetroDialog dialog, MetroDialogSettings settings = null) { Action action1 = null; Func <Task> func2 = null; window.Dispatcher.VerifyAccess(); if (!window.metroActiveDialogContainer.Children.Contains(dialog) && !window.metroInactiveDialogContainer.Children.Contains(dialog)) { throw new InvalidOperationException("The provided dialog is not visible in the specified window."); } window.SizeChanged -= dialog.SizeChangedHandler; dialog.OnClose(); Task task = window.Dispatcher.Invoke <Task>(new Func <Task>(dialog._WaitForCloseAsync)); return(task.ContinueWith <Task>((Task a) => { if (DialogManager.DialogClosed != null) { Dispatcher dispatcher = window.Dispatcher; Action u003cu003e9_1 = action1; if (u003cu003e9_1 == null) { Action dialogClosed = () => DialogManager.DialogClosed(window, new DialogStateChangedEventArgs()); Action action = dialogClosed; action1 = dialogClosed; u003cu003e9_1 = action; } dispatcher.BeginInvoke(u003cu003e9_1, new object[0]); } Dispatcher dispatcher1 = window.Dispatcher; Func <Task> u003cu003e9_2 = func2; if (u003cu003e9_2 == null) { Func <Task> func = () => { window.RemoveDialog(dialog); return DialogManager.HandleOverlayOnHide(settings, window); }; Func <Task> func1 = func; func2 = func; u003cu003e9_2 = func1; } return dispatcher1.Invoke <Task>(u003cu003e9_2); }).Unwrap()); }