private static Task HandleOverlayOnHide(MetroDialogSettings settings, MetroWindow window) { Task result = null; if (!window.metroActiveDialogContainer.Children.OfType <BaseMetroDialog>().Any()) { result = (settings == null || settings.AnimateHide ? window.HideOverlayAsync() : Task.Factory.StartNew(() => window.Dispatcher.Invoke(new Action(window.HideOverlay)))); } else { var tcs = new System.Threading.Tasks.TaskCompletionSource <object>(); tcs.SetResult(null); result = tcs.Task; } result.ContinueWith(task => { window.Invoke(() => { if (window.metroActiveDialogContainer.Children.Count == 0) { window.SetValue(MetroWindow.IsCloseButtonEnabledWithDialogPropertyKey, BooleanBoxes.TrueBox); window.RestoreFocus(); } else { var onTopShownDialogSettings = window.metroActiveDialogContainer.Children.OfType <BaseMetroDialog>().LastOrDefault()?.DialogSettings; var isCloseButtonEnabled = window.ShowDialogsOverTitleBar || onTopShownDialogSettings == null || onTopShownDialogSettings.OwnerCanCloseWithDialog; window.SetValue(MetroWindow.IsCloseButtonEnabledWithDialogPropertyKey, BooleanBoxes.Box(isCloseButtonEnabled)); } }); }); return(result); }
private static void RemoveDialog(this MetroWindow window, BaseMetroDialog dialog) { if (window.metroActiveDialogContainer.Children.Contains(dialog)) { window.metroActiveDialogContainer.Children.Remove(dialog); //remove the dialog from the container // if there's an inactive dialog, bring it to the front var dlg = window.metroInactiveDialogContainer.Children.Cast <UIElement>().LastOrDefault(); if (dlg != null) { window.metroInactiveDialogContainer.Children.Remove(dlg); window.metroActiveDialogContainer.Children.Add(dlg); } } else { window.metroInactiveDialogContainer.Children.Remove(dialog); } if (window.metroActiveDialogContainer.Children.Count == 0) { window.RestoreFocus(); } window.SetValue(MetroWindow.IsAnyDialogOpenPropertyKey, window.metroActiveDialogContainer.Children.Count > 0); }