Example #1
0
        /// <summary>
        /// Adds a TMP 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="HideTMPDialogAsync"/>.</para>
        /// <para>You can still close the resulting dialog with <see cref="HideTMPDialogAsync"/>.</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 ShowTMPDialogAsync(this TMPWindow window, BaseTMPDialog dialog, TMPDialogSettings settings = null)
        {
            window.Dispatcher.VerifyAccess();
            if (window.tmpDialogContainer.Children.Contains(dialog))
            {
                throw new InvalidOperationException("The provided dialog is already visible in the specified window.");
            }

            return(HandleOverlayOnShow(settings, window).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());
                }
            }))))));
        }
Example #2
0
        public static BaseTMPDialog ShowModalDialogExternally(this BaseTMPDialog dialog)
        {
            Window win = SetupExternalDialogWindow(dialog);

            dialog.OnShown();
            win.ShowDialog();

            return(dialog);
        }
Example #3
0
        private static SizeChangedEventHandler SetupAndOpenDialog(TMPWindow window, BaseTMPDialog dialog)
        {
            dialog.SetValue(Panel.ZIndexProperty, (int)window.overlayBox.GetValue(Panel.ZIndexProperty) + 1);
            dialog.MinHeight = window.ActualHeight / 4.0;
            dialog.MaxHeight = window.ActualHeight;

            SizeChangedEventHandler sizeHandler = (sender, args) =>
            {
                dialog.MinHeight = window.ActualHeight / 4.0;
                dialog.MaxHeight = window.ActualHeight;
            };

            window.SizeChanged += sizeHandler;

            window.tmpDialogContainer.Children.Add(dialog); //add the dialog to the container

            dialog.OnShown();

            return(sizeHandler);
        }