Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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());
        }
Ejemplo n.º 4
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);
        }