예제 #1
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());
        }
예제 #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());
        }
예제 #3
0
        public Task HideMetroDialogAsync(object context
                                         , IBaseMetroDialogFrame dialog
                                         , IMetroDialogFrameSettings settings = null)
        {
            var metroWindow = GetMetroWindow(context);

            return(metroWindow.Dispatcher.Invoke(() => _dialogManager.HideMetroDialogAsync(metroWindow, dialog, settings)));
        }
예제 #4
0
        /// <summary>
        /// Initializes a new DialogFrame object.
        /// </summary>
        /// <param name="owningWindow">The window that is the parent of the dialog.</param>
        /// <param name="settings">The settings for the message dialog.</param>
        protected DialogFrame(IMetroWindow owningWindow
                              , IMetroDialogFrameSettings settings)
            : this()
        {
            DialogSettings = settings ?? new MetroDialogFrameSettings();

            OwningWindow = owningWindow;
        }
예제 #5
0
        /// <summary>
        /// Class constructor
        /// </summary>
        public ContentDialogServiceImpl()
        {
            _dialogManager     = new DialogManager();
            _dialogCoordinator = new DialogCoordinator(_dialogManager);
            _MsgBox            = new MessageBoxServiceImpl(this);

            _DialogSettings = new MetroDialogFrameSettings();
        }
예제 #6
0
        /// <summary>
        /// Class constructor from parameters.
        /// </summary>
        /// <param name="parentWindow"></param>
        /// <param name="settings"></param>
        public CustomDialog(IMetroWindow parentWindow
                            , IMetroDialogFrameSettings settings)
            : base(parentWindow, settings)
        {
            InitializeComponent();
            this.DialogThumb = null;

            this.Loaded += MsgBoxDialog_Loaded;
        }
예제 #7
0
        public async Task <int> ShowMetroDialogAsync(object context
                                                     , IMsgBoxDialogFrame <int> dialog
                                                     , IMetroDialogFrameSettings settings = null)
        {
            var metroWindow = GetMetroWindow(context);

            var result = await _dialogManager.ShowMetroDialogAsync(metroWindow, dialog);

            return(result);
        }
예제 #8
0
        /// <summary>
        /// Creates a modal dialog outside of the current main window.
        /// </summary>
        /// <param name="metroWindow">The MetroWindow</param>
        /// <param name="dlgControl">The outside modal window to be owned by a given <seealso cref="IMetroWindow"/></param>
        /// <param name="settings">Optional settings that override the global metro dialog settings.</param>
        /// <returns>The result that was entered or 0 if the user escape keyed the dialog...</returns>
        public int ShowModalDialogExternal(
            IMetroWindow metroWindow
            , IMsgBoxDialogFrame <int> dlgControl
            , IMetroDialogFrameSettings settings = null)
        {
            settings = settings ?? new MetroDialogFrameSettings();

            // Create the outter dialog window that hosts the dialog control
            var dlgWindow = _metroWindowService.CreateExternalWindow();

            // The window is visible on top of the mainWindow
            dlgWindow = CreateModalExternalWindow(metroWindow, dlgWindow);

            // Release the dialog opened event if there are any subscribers
            if (this.DialogOpened != null)
            {
                metroWindow.Dispatcher.BeginInvoke(new Action(() => DialogOpened(this, new DialogStateChangedEventArgs())));
            }

            if (settings.MsgBoxMode == StaticMsgBoxModes.ExternalMoveable)
            {
                // Relay drag event from thumb to outer window to let user drag the dialog
                if (dlgControl.DialogThumb != null && dlgWindow is IMetroWindow)
                {
                    ((IMetroWindow)dlgWindow).SetWindowEvents(dlgControl.DialogThumb);
                }
            }

            dlgWindow.Content = dlgControl;

            int result = 0;

            dlgControl.WaitForButtonPressAsync().ContinueWith(task =>
            {
                result = task.Result;
                dlgWindow.Invoke(dlgWindow.Close);
            });

            HandleOverlayOnShow(metroWindow, settings);
            dlgWindow.ShowDialog();

            // Release the dialog closed event if there are any subscribers
            if (this.DialogClosed != null)
            {
                metroWindow.Dispatcher.BeginInvoke(new Action(() => DialogClosed(this, new DialogStateChangedEventArgs())));
            }

            HandleOverlayOnHide(metroWindow, settings);

            return(result);
        }
예제 #9
0
        /// <summary>
        /// Creates a MsgBoxDialog inside 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 Task <MsgBoxResult> ShowMsgBoxAsync(
            IMetroWindow metroWindow
            , IMsgBoxDialogFrame <MsgBoxResult> dialog
            , IMetroDialogFrameSettings settings = null)
        {
            metroWindow.Dispatcher.VerifyAccess();
            return(this.HandleOverlayOnShow(metroWindow, settings).ContinueWith(z =>
            {
                return (Task <MsgBoxResult>)metroWindow.Dispatcher.Invoke(new Func <Task <MsgBoxResult> >(() =>
                {
                    settings = settings ?? new MetroDialogFrameSettings();

                    SizeChangedEventHandler sizeHandler = this.SetupAndOpenDialog(metroWindow, dialog);
                    dialog.SizeChangedHandler = sizeHandler;

                    // Call this method in the dialog to wait until the dialog is closing ...
                    return dialog.WaitForLoadAsync().ContinueWith(x =>
                    {
                        if (DialogOpened != null)
                        {
                            metroWindow.Dispatcher.BeginInvoke(new Action(() => DialogOpened(this, new DialogStateChangedEventArgs())));
                        }

                        return dialog.WaitForButtonPressAsync().ContinueWith(y =>
                        {
                            //once a button as been clicked, begin removing the dialog.

                            dialog.OnClose();

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

                            Task closingTask = (Task)metroWindow.Dispatcher.Invoke(new Func <Task>(() => dialog._WaitForCloseAsync()));
                            return closingTask.ContinueWith(a =>
                            {
                                return ((Task)metroWindow.Dispatcher.Invoke(new Func <Task>(() =>
                                {
                                    metroWindow.SizeChanged -= sizeHandler;

                                    this.RemoveDialog(metroWindow, dialog);

                                    return this.HandleOverlayOnHide(metroWindow, settings);
                                }))).ContinueWith(y3 => y).Unwrap();
                            });
                        }).Unwrap();
                    }).Unwrap().Unwrap();
                }));
            }).Unwrap());
        }
예제 #10
0
 private Task HandleOverlayOnShow(IMetroWindow metroWindow
                                  , IMetroDialogFrameSettings settings)
 {
     if (!metroWindow.MetroActiveDialogContainer.Children.OfType <IBaseMetroDialogFrame>().Any())
     {
         return(settings == null || settings.AnimateShow ? metroWindow.ShowOverlayAsync() : Task.Factory.StartNew(() => metroWindow.Dispatcher.Invoke(new Action(metroWindow.ShowOverlay))));
     }
     else
     {
         var tcs = new System.Threading.Tasks.TaskCompletionSource <object>();
         tcs.SetResult(null);
         return(tcs.Task);
     }
 }
예제 #11
0
        /// <summary>
        /// Constructor from custom view and optional viewmodel.
        /// </summary>
        /// <param name="contentView"></param>
        /// <param name="viewModel"></param>
        /// <param name="settings"></param>
        public CustomDialog(object contentView
                            , object viewModel = null
                            , IMetroDialogFrameSettings settings = null)
            : base(null, settings)
        {
            InitializeComponent();

            // Set the display view here ...
            this.PART_Msg_Content.ChromeContent = contentView;
            this.DialogThumb = this.PART_Msg_Content.PART_DialogTitleThumb;

            // Get a view and bind datacontext to it
            this.DataContext = viewModel;

            this.Loaded += MsgBoxDialog_Loaded;
        }
예제 #12
0
        /// <summary>
        /// Constructor from custom view and optional viewmodel.
        /// </summary>
        /// <param name="parentWindow"></param>
        /// <param name="content"></param>
        /// <param name="viewnodel"></param>
        /// <param name="settings"></param>
        internal MsgBoxDialog(IMetroWindow parentWindow
                              , FrameworkElement content
                              , object viewnodel = null
                              , IMetroDialogFrameSettings settings = null)
            : base(parentWindow, settings)
        {
            InitializeComponent();

            // Set the display view here ...
            this.PART_Msg_Content.ChromeContent = content;
            this.DialogThumb = this.PART_Msg_Content.PART_DialogTitleThumb;

            // Get a view and bind datacontext to it
            this.DataContext = viewnodel;

            this.Loaded += MsgBoxDialog_Loaded;
        }
예제 #13
0
        /// <summary>
        /// Creates an External MsgBox dialog outside of the main window.
        /// </summary>
        /// <param name="metroWindow"></param>
        /// <param name="dlgControl"></param>
        /// <param name="settings"></param>
        /// <returns></returns>
        public MsgBoxResult ShowModalDialogExternal(
            IMetroWindow metroWindow
            , IMsgBoxDialogFrame <MsgBoxResult> dlgControl
            , IMetroDialogFrameSettings settings = null)
        {
            settings = settings ?? new MetroDialogFrameSettings();

            // Create the outter dialog window that hosts the dialog control
            var dlgWindow = _metroWindowService.CreateExternalWindow();

            // The window is visible on top of the mainWindow
            dlgWindow = CreateModalExternalWindow(metroWindow, dlgWindow);

            if (settings.MsgBoxMode == StaticMsgBoxModes.ExternalMoveable)
            {
                // Relay drag event from thumb to outer window to let user drag the dialog
                if (dlgControl.DialogThumb != null && dlgWindow is IMetroWindow)
                {
                    ((IMetroWindow)dlgWindow).SetWindowEvents(dlgControl.DialogThumb);
                }
            }

            dlgWindow.Content = dlgControl;

            MsgBoxResult result = MsgBoxResult.None;

            dlgControl.WaitForButtonPressAsync().ContinueWith(task =>
            {
                result = task.Result;
                dlgWindow.Invoke(dlgWindow.Close);
            });

            HandleOverlayOnShow(metroWindow, settings);
            dlgWindow.ShowDialog();
            HandleOverlayOnHide(metroWindow, settings);

            return(result);
        }