/// <summary> /// Creates a ContentDialog inside of the current window. /// </summary> /// <param name="window">The CushWindow.</param> /// <param name="content">The ContentDialog to display.</param> /// <param name="settings">Optional settings that override the global metro dialog settings.</param> /// <returns>A task promising the result of which button was pressed.</returns> public static Task<MessageDialogResult> ShowDialogAsync(this CushWindow window, ContentDialog content, DialogSettings settings = null) { ThrowHelper.IfNullThenThrow(() => content); if (settings == null) settings = content.DialogSettings ?? window.DialogOptions ?? new DialogSettings(); window.Dispatcher.VerifyAccess(); return HandleOverlayOnShow(settings, window).ContinueWith(z => window.Dispatcher.Invoke(() => { var dialog = GetDialog(window, content, settings); var sizeHandler = SetupAndOpenDialog(window, dialog); dialog.SizeChangedHandler = sizeHandler; return dialog.WaitForLoadAsync().ContinueWith(x => { window.OnDialogOpened(); return dialog.WaitForButtonPressAsync().ContinueWith(y => { //once a button as been clicked, begin removing the dialog. dialog.OnClose(); window.OnDialogClosed(); var closingTask = window.Dispatcher.Invoke(dialog.WaitForCloseAsync); return closingTask.ContinueWith(a => (window.Dispatcher.Invoke(() => { window.SizeChanged -= sizeHandler; window.DialogContainer.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(); }
private static ContentDialog CreateDialog(CushWindow window, ContentDialog content, DialogSettings settings) { if (settings == null) settings = window.DialogOptions; // Pull the content out of the dialog and put it into a new dialog. // (For some reason, using the dialog directly doesn't work.) var body = content; var bodyContext = (content).DataContext; //create the dialog control var dialog = new ContentDialog(window, settings) { Content = body, Guid = content.Guid, DataContext = bodyContext }; return dialog; }
private static ContentDialog GetDialog(CushWindow window, ContentDialog content, DialogSettings settings) { // Return the existing dialog, if it exists. // Otherwise, create a new one. return window.DialogContainer.Children.Cast<ContentDialog>() .FirstOrDefault(item => item.Guid == content.Guid) ?? CreateDialog(window, content, settings); }
public static void SetDialogResult(ContentDialog target, bool? value) { target.SetValue(DialogResultProperty, value); }