Beispiel #1
0
        private void RemoveDialog(IMetroWindow metroWindow
                                  , IBaseMetroDialogFrame dialog)
        {
            if (metroWindow.MetroActiveDialogContainer.Children.Contains(dialog as UIElement))
            {
                // remove the dialog from the container
                metroWindow.MetroActiveDialogContainer.Children.Remove(dialog as UIElement);

                // if there's an inactive dialog, bring it to the front
                var dlg = metroWindow.MetroInactiveDialogContainer.Children.Cast <UIElement>().LastOrDefault();
                if (dlg != null)
                {
                    metroWindow.MetroInactiveDialogContainer.Children.Remove(dlg);
                    metroWindow.MetroActiveDialogContainer.Children.Add(dlg);
                }
            }
            else
            {
                metroWindow.MetroInactiveDialogContainer.Children.Remove(dialog as UIElement);
            }

            if (metroWindow.MetroActiveDialogContainer.Children.Count == 0)
            {
                metroWindow.RestoreFocus();
            }
        }
Beispiel #2
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 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());
        }
Beispiel #3
0
        /// <summary>
        /// Hides a visible Metro Dialog instance.
        /// </summary>
        /// <param name="window">The window with the dialog that is visible.</param>
        /// <param name="dialog">The dialog instance to hide.</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 not visible in the window.
        /// This happens if <see cref="ShowMetroDialogAsync"/> hasn't been called before.
        /// </exception>
        public Task HideMetroDialogAsync(
            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 not visible in the specified window.");
            }

            metroWindow.SizeChanged -= dialog.SizeChangedHandler;

            dialog.OnClose();

            Task closingTask = (Task)metroWindow.Dispatcher.Invoke(new Func <Task>(dialog._WaitForCloseAsync));

            return(closingTask.ContinueWith(a =>
            {
                if (DialogClosed != null)
                {
                    metroWindow.Dispatcher.BeginInvoke(new Action(() => DialogClosed(this, new DialogStateChangedEventArgs())));
                }

                return (Task)metroWindow.Dispatcher.Invoke(new Func <Task>(() =>
                {
                    this.RemoveDialog(metroWindow, dialog);

                    return this.HandleOverlayOnHide(metroWindow, settings);
                }));
            }).Unwrap());
        }
Beispiel #4
0
        public Task HideMetroDialogAsync(object context
                                         , IBaseMetroDialogFrame dialog
                                         , IMetroDialogFrameSettings settings = null)
        {
            var metroWindow = GetMetroWindow(context);

            return(metroWindow.Dispatcher.Invoke(() => _dialogManager.HideMetroDialogAsync(metroWindow, dialog, settings)));
        }
Beispiel #5
0
        /// <summary>
        /// Method executes when Close (x) window or demo button is clicked
        ///
        /// 1> This invokes the bound ICommand CloseCommand which in turn
        ///    2> will invoke the event that is bound to this method...
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void CloseCustomDialog(object sender, DialogStateChangedEventArgs e)
        {
            var dlg     = GetService <IContentDialogService>();
            var manager = dlg.Manager;

            await manager.HideMetroDialogAsync(_parentWindow, _dialog);

            _dialog       = null;
            _parentWindow = null;
        }
Beispiel #6
0
        /// <summary>
        /// Creates a InputDialog outside of the current window.
        /// </summary>
        /// <param name="window">The MetroWindow</param>
        /// <param name="title">The title of the MessageDialog.</param>
        /// <param name="message">The message contained within the MessageDialog.</param>
        /// <param name="settings">Optional settings that override the global metro dialog settings.</param>
        /// <returns>The text that was entered or null (Nothing in Visual Basic) if the user cancelled the operation.</returns>
        ////        public string ShowModalInputExternal(
        ////            IMetroWindow metroWindow
        ////          , string title
        ////          , string message
        ////          , Window win
        ////          , IMetroDialogFrameSettings settings = null)
        ////        {
        ////            win = CreateModalExternalWindow(metroWindow, win);
        ////
        ////            settings = settings ?? new MetroDialogFrameSettings();
        ////
        ////            //create the dialog control
        ////            var dialog = new InputDialog(metroWindow, settings)
        ////            {
        ////                Message = message,
        ////                Title = title,
        ////                Input = settings.DefaultText
        ////            };
        ////
        ////            ////SetDialogFontSizes(settings, dialog);
        ////
        ////            win.Content = dialog;
        ////
        ////            string result = null;
        ////            dialog.WaitForButtonPressAsync().ContinueWith(task =>
        ////            {
        ////                result = task.Result;
        ////                win.Invoke(win.Close);
        ////            });
        ////
        ////            HandleOverlayOnShow(metroWindow, settings);
        ////            win.ShowDialog();
        ////            HandleOverlayOnHide(metroWindow, settings);
        ////            return result;
        ////        }

        /// <summary>
        /// Creates a MessageDialog ouside of the current window.
        /// </summary>
        /// <param name="window">The MetroWindow</param>
        /// <param name="title">The title of the MessageDialog.</param>
        /// <param name="message">The message contained within the MessageDialog.</param>
        /// <param name="style">The type of buttons to use.</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 MessageDialogResult ShowModalMessageExternal(
        ////              IMetroWindow metroWindow
        ////            , string title
        ////            , string message
        ////            , Window dialogWindow
        ////            , MessageDialogStyle style = MessageDialogStyle.Affirmative
        ////            , IMetroDialogFrameSettings settings = null)
        ////        {
        ////            dialogWindow = CreateModalExternalWindow(metroWindow, dialogWindow);
        ////
        ////            settings = settings ?? new MetroDialogFrameSettings();
        ////
        ////            //create the dialog control
        ////            var dialog = new MessageDialog(metroWindow, settings)
        ////            {
        ////                Message = message,
        ////                Title = title,
        ////                ButtonStyle = style
        ////            };
        ////
        ////            ////SetDialogFontSizes(settings, dialog);
        ////
        ////            dialogWindow.Content = dialog;
        ////
        ////            MessageDialogResult result = MessageDialogResult.Affirmative;
        ////            dialog.WaitForButtonPressAsync().ContinueWith(task =>
        ////            {
        ////                result = task.Result;
        ////                dialogWindow.Invoke(dialogWindow.Close);
        ////            });
        ////
        ////            HandleOverlayOnShow(metroWindow, settings);
        ////            dialogWindow.ShowDialog();
        ////            HandleOverlayOnHide(metroWindow, settings);
        ////            return result;
        ////        }

        /// <summary>
        /// Creates a LoginDialog outside of the current window.
        /// </summary>
        /// <param name="metroWindow">The window that is the parent of the dialog.</param>
        /// <param name="title">The title of the LoginDialog.</param>
        /// <param name="message">The message contained within the LoginDialog.</param>
        /// <param name="dialogWindow"></param>
        /// <param name="settings">Optional settings that override the global metro dialog settings.</param>
        /// <returns>The text that was entered or null (Nothing in Visual Basic) if the user cancelled the operation.</returns>
        ////        public ILoginDialogData ShowModalLoginExternal(
        ////              IMetroWindow metroWindow
        ////            , string title
        ////            , string message
        ////            , Window dialogWindow
        ////            , ILoginDialogSettings settings = null)
        ////        {
        ////            dialogWindow = CreateModalExternalWindow(metroWindow, dialogWindow);
        ////
        ////            settings = settings ?? new LoginDialogSettings();
        ////
        ////            //create the dialog control
        ////            LoginDialog dialog = new LoginDialog(metroWindow, settings)
        ////            {
        ////                Title = title,
        ////                Message = message
        ////            };
        ////
        ////            ////SetDialogFontSizes(settings, dialog);
        ////
        ////            dialogWindow.Content = dialog;
        ////
        ////            ILoginDialogData result = null;
        ////            dialog.WaitForButtonPressAsync().ContinueWith(task =>
        ////            {
        ////                result = task.Result;
        ////                dialogWindow.Invoke(dialogWindow.Close);
        ////            });
        ////
        ////            HandleOverlayOnShow(metroWindow, settings);
        ////            dialogWindow.ShowDialog();
        ////            HandleOverlayOnHide(metroWindow, settings);
        ////
        ////            return result;
        ////        }
        #endregion Modal External dialog

        private void AddDialog(IMetroWindow metroWindow
                               , IBaseMetroDialogFrame dialog)
        {
            metroWindow.StoreFocus();

            // if there's already an active dialog, move to the background
            var activeDialog = metroWindow.MetroActiveDialogContainer.Children.Cast <UIElement>().SingleOrDefault();

            if (activeDialog != null)
            {
                metroWindow.MetroActiveDialogContainer.Children.Remove(activeDialog);
                metroWindow.MetroInactiveDialogContainer.Children.Add(activeDialog);
            }

            // add the dialog to the container}
            metroWindow.MetroActiveDialogContainer.Children.Add(dialog as UIElement);
        }
Beispiel #7
0
        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);
        }