/// <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 Task ShowMetroDialogAsync( IMetroWindow metroWindow , IBaseMetroDialogFrame dialog , IMetroDialogFrameSettings settings = null) { metroWindow.Dispatcher.VerifyAccess(); if (metroWindow.MetroActiveDialogContainer.Children.Contains(dialog as UIElement) || metroWindow.MetroInactiveDialogContainer.Children.Contains(dialog as UIElement)) { throw new InvalidOperationException("The provided dialog is already visible in the specified window."); } return(this.HandleOverlayOnShow(metroWindow, settings).ContinueWith(z => { return (Task)metroWindow.Dispatcher.Invoke(new Func <Task>(() => { settings = settings ?? new MetroDialogFrameSettings(); SizeChangedEventHandler sizeHandler = this.SetupAndOpenDialog(metroWindow, dialog); dialog.SizeChangedHandler = sizeHandler; return dialog.WaitForLoadAsync().ContinueWith(x => { dialog.OnShown(); if (DialogOpened != null) { metroWindow.Dispatcher.BeginInvoke(new Action(() => DialogOpened(this, new DialogStateChangedEventArgs()))); } }); })); }).Unwrap()); }
private SizeChangedEventHandler SetupAndOpenDialog( IMetroWindow metroWindow , IBaseMetroDialogFrame dialog) { dialog.SetZIndex((int)metroWindow.OverlayBox.GetValue(Panel.ZIndexProperty) + 1); dialog.MinHeight = metroWindow.ActualHeight / 4.0; dialog.MaxHeight = metroWindow.ActualHeight; SizeChangedEventHandler sizeHandler = (sender, args) => { dialog.MinHeight = metroWindow.ActualHeight / 4.0; dialog.MaxHeight = metroWindow.ActualHeight; }; metroWindow.SizeChanged += sizeHandler; this.AddDialog(metroWindow, dialog); dialog.OnShown(); return(sizeHandler); }