OnShown() protected method

protected OnShown ( ) : void
return void
Example #1
0
        /// <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 static Task ShowMetroDialogAsync(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 already visible in the specified window.");
            }

            return(HandleOverlayOnShow(settings, window).ContinueWith(z =>
            {
                return (Task)window.Dispatcher.Invoke(new Func <Task>(() =>
                {
                    settings = settings ?? window.MetroDialogOptions;

                    SetDialogFontSizes(settings, dialog);

                    SizeChangedEventHandler sizeHandler = SetupAndOpenDialog(window, dialog);
                    dialog.SizeChangedHandler = sizeHandler;

                    return dialog.WaitForLoadAsync().ContinueWith(x =>
                    {
                        dialog.OnShown();

                        if (DialogOpened != null)
                        {
                            window.Dispatcher.BeginInvoke(new Action(() => DialogOpened(window, new DialogStateChangedEventArgs())));
                        }
                    });
                }));
            }).Unwrap());
        }
        private static SizeChangedEventHandler SetupAndOpenDialog(MetroWindow window, BaseMetroDialog dialog)
        {
            dialog.SetValue(Panel.ZIndexProperty, (int)window.overlayBox.GetValue(Panel.ZIndexProperty) + 1);
            dialog.MinHeight = window.ActualHeight / 4.0;

            SizeChangedEventHandler sizeHandler = null; //an event handler for auto resizing an open dialog.

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

            window.SizeChanged += sizeHandler;

            //window.overlayBox.Visibility = Visibility.Visible; //activate the overlay effect

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

            dialog.OnShown();

            if (window.TextBlockStyle != null && !dialog.Resources.Contains(typeof(TextBlock)))
            {
                dialog.Resources.Add(typeof(TextBlock), window.TextBlockStyle);
            }
            return(sizeHandler);
        }
Example #3
0
        /// <summary>
        /// Adds a Metro 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="HideMetroDialogAsync"/>.</para>
        /// <para>You can still close the resulting dialog with <see cref="HideMetroDialogAsync"/>.</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 ShowMetroDialogAsync(this MetroWindow window, BaseMetroDialog dialog)
        {
            window.Dispatcher.VerifyAccess();
            if (window.metroDialogContainer.Children.Contains(dialog))
            {
                throw new InvalidOperationException("The provided dialog is already visible in the specified window.");
            }

            return(window.ShowOverlayAsync().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 #4
0
        public static BaseMetroDialog ShowDialogExternally(this BaseMetroDialog dialog)
        {
            Window window = DialogManager.SetupExternalDialogWindow(dialog);

            dialog.OnShown();
            window.Show();
            return(dialog);
        }
Example #5
0
        public static BaseMetroDialog ShowModalDialogExternally(this BaseMetroDialog dialog)
        {
            Window win = SetupExternalDialogWindow(dialog);

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

            return(dialog);
        }
        /// <summary>
        /// Create and show an external modal dialog.
        /// </summary>
        /// <param name="dialog">The dialog which will be shown externally.</param>
        /// <param name="windowOwner">The owner for the external window. If it's null the main window will be use.</param>
        /// <returns>The given dialog.</returns>
        public static BaseMetroDialog ShowModalDialogExternally(this BaseMetroDialog dialog, [CanBeNull] Window windowOwner = null)
        {
            Window win = SetupExternalDialogWindow(dialog, windowOwner);

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

            return(dialog);
        }
Example #7
0
        private static SizeChangedEventHandler SetupAndOpenDialog(MetroWindow window, BaseMetroDialog dialog)
        {
            dialog.SetValue(Panel.ZIndexProperty, (int)window.overlayBox.GetValue(Panel.ZIndexProperty) + 1);
            dialog.MinHeight = window.ActualHeight / 4;
            dialog.MaxHeight = window.ActualHeight;
            SizeChangedEventHandler minHeight = (object sender, SizeChangedEventArgs e) => {
                dialog.MinHeight = window.ActualHeight / 4;
                dialog.MaxHeight = window.ActualHeight;
            };

            window.SizeChanged += minHeight;
            window.AddDialog(dialog);
            dialog.OnShown();
            return(minHeight);
        }
Example #8
0
        private static SizeChangedEventHandler SetupAndOpenDialog(MetroWindow window, BaseMetroDialog 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.AddDialog(dialog);

            dialog.OnShown();

            return(sizeHandler);
        }
Example #9
0
        private static SizeChangedEventHandler SetupAndOpenDialog(MetroWindow window, BaseMetroDialog dialog)
        {
            dialog.SetValue(Panel.ZIndexProperty, (int)(window.overlayBox?.GetValue(Panel.ZIndexProperty) ?? 0) + 1);

            var fixedMinHeight = dialog.MinHeight > 0;
            var fixedMaxHeight = dialog.MaxHeight is not double.PositiveInfinity && dialog.MaxHeight > 0;

            void CalculateMinAndMaxHeight()
            {
                if (!fixedMinHeight)
                {
                    dialog.SetCurrentValue(FrameworkElement.MinHeightProperty, window.ActualHeight / 4.0);
                }

                if (!fixedMaxHeight)
                {
                    dialog.SetCurrentValue(FrameworkElement.MaxHeightProperty, window.ActualHeight);
                }
                else
                {
                    dialog.SetCurrentValue(FrameworkElement.MinHeightProperty, Math.Min(dialog.MinHeight, dialog.MaxHeight));
                }
            }

            CalculateMinAndMaxHeight();

            void OnWindowSizeChanged(object sender, SizeChangedEventArgs args)
            {
                CalculateMinAndMaxHeight();
            }

            window.SizeChanged += OnWindowSizeChanged;

            window.AddDialog(dialog);

            dialog.OnShown();

            return(OnWindowSizeChanged);
        }
        private static SizeChangedEventHandler SetupAndOpenDialog(MetroWindow window, string title, BaseMetroDialog dialog)
        {
            dialog.SetValue(Panel.ZIndexProperty, (int)window.overlayBox.GetValue(Panel.ZIndexProperty) + 1);
            dialog.MinHeight = window.ActualHeight / 4.0;
            dialog.Title = title;

            SizeChangedEventHandler sizeHandler = null; //an event handler for auto resizing an open dialog.
            sizeHandler = new SizeChangedEventHandler((sender, args) =>
            {
                dialog.MinHeight = window.ActualHeight / 4.0;
            });

            window.SizeChanged += sizeHandler;

            //window.overlayBox.Visibility = Visibility.Visible; //activate the overlay effect

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

            dialog.OnShown();

            if (window.TextBlockStyle != null && !dialog.Resources.Contains(typeof(TextBlock)))
            {
                dialog.Resources.Add(typeof(TextBlock), window.TextBlockStyle);
            }
            return sizeHandler;
        }
Example #11
0
        private static SizeChangedEventHandler SetupAndOpenDialog(MetroWindow window, BaseMetroDialog dialog)
        {
            dialog.SetValue(Panel.ZIndexProperty, (int)window.overlayBox.GetValue(Panel.ZIndexProperty) + 1);
            dialog.MinHeight = window.ActualHeight / 4.0;
            dialog.MaxHeight = window.ActualHeight;

            SizeChangedEventHandler sizeHandler = null; //an event handler for auto resizing an open dialog.
            sizeHandler = new SizeChangedEventHandler((sender, args) =>
            {
                dialog.MinHeight = window.ActualHeight / 4.0;
                dialog.MaxHeight = window.ActualHeight;
            });

            window.SizeChanged += sizeHandler;

            //window.overlayBox.Visibility = Visibility.Visible; //activate the overlay effect

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

            dialog.OnShown();

            return sizeHandler;
        }
Example #12
0
        /// <summary>
        /// Adds a Metro Dialog instance to the specified window and makes it visible.
        /// </summary>
        /// <param name="window">The owning window of the dialog.</param>
        /// <param name="title">The title to be set in 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 ShowMetroDialogAsync(this MetroWindow window, BaseMetroDialog dialog)
        {
            window.Dispatcher.VerifyAccess();
            if (window.metroDialogContainer.Children.Contains(dialog))
                throw new InvalidOperationException("The provided dialog is already visible in the specified window.");

            return window.ShowOverlayAsync().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 #13
0
        private static SizeChangedEventHandler SetupAndOpenDialog(MetroWindow window, BaseMetroDialog 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.metroDialogContainer.Children.Add(dialog); //add the dialog to the container

            dialog.OnShown();

            return sizeHandler;
        }