Exemplo n.º 1
0
        /// <summary>
        /// Configure <see cref="IDialogWindow"/> and <see cref="IDialogAware"/> events.
        /// </summary>
        /// <param name="dialogWindow">The hosting window.</param>
        /// <param name="callback">The action to perform when the dialog is closed.</param>
        internal static void ConfigureDialogWindowEvents(this IDialogWindow dialogWindow, Action <IDialogResult> callback)
        {
            Action <IDialogResult> requestCloseHandler = null;

            requestCloseHandler = (o) =>
            {
                dialogWindow.Result = o;
                dialogWindow.Close();
            };

            RoutedEventHandler loadedHandler = null;

            loadedHandler = (o, e) =>
            {
                dialogWindow.Loaded -= loadedHandler;
                dialogWindow.GetDialogViewModel().RequestClose += requestCloseHandler;
            };
            dialogWindow.Loaded += loadedHandler;

            CancelEventHandler closingHandler = null;

            closingHandler = (o, e) =>
            {
                if (!dialogWindow.GetDialogViewModel().CanCloseDialog())
                {
                    e.Cancel = true;
                }
            };
            dialogWindow.Closing += closingHandler;

            EventHandler closedHandler = null;

            closedHandler = (o, e) =>
            {
                dialogWindow.Closed  -= closedHandler;
                dialogWindow.Closing -= closingHandler;
                dialogWindow.GetDialogViewModel().RequestClose -= requestCloseHandler;

                dialogWindow.GetDialogViewModel().OnDialogClosed();

                if (dialogWindow.Result == null)
                {
                    dialogWindow.Result = new DialogResult();
                }

                callback?.Invoke(dialogWindow.Result);

                dialogWindow.DataContext = null;
                dialogWindow.Content     = null;
            };
            dialogWindow.Closed += closedHandler;
        }
 private static void CloseDialog(IDialogWindow dialog)
 {
     // For a TreeViewItem the double-click event bubbles up and fires for every ancestor TreeViewItem as well
     // We only want to handle it once to close the dialog (ignore repeated attempts to close dialog)
     if (dialog != null)
     {
         if (dialog.DialogResult != true)
         {
             dialog.DialogResult = true;
             dialog.Close();
         }
     }
 }
Exemplo n.º 3
0
 private void CloseDialog(IDialogWindow dialog)
 {
     if (!this.patternManager.Products.Any(product => product.InstanceName.Equals(this.productName, StringComparison.OrdinalIgnoreCase)))
     {
         dialog.DialogResult = true;
         dialog.Close();
     }
     else
     {
         this.userMessageService.ShowError(string.Format(
                                               CultureInfo.CurrentCulture,
                                               Resources.AddNewProductViewModel_ProductNameDuplicated,
                                               this.productName));
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Configure <see cref="IDialogWindow"/> and <see cref="IDialogAware"/> events.
        /// </summary>
        /// <param name="dialogWindow">The hosting window.</param>
        /// <param name="callback">The action to perform when the dialog is closed.</param>
        protected virtual void ConfigureDialogWindowEvents(IDialogWindow dialogWindow, Action <IDialogResult> callback)
        {
            void requestCloseHandler(IDialogResult o)
            {
                dialogWindow.Result = o;
                dialogWindow.Close();
            }

            void loadedHandler(object o, RoutedEventArgs e)
            {
                dialogWindow.Loaded -= loadedHandler;
                dialogWindow.GetDialogViewModel().RequestClose += requestCloseHandler;
            }

            dialogWindow.Loaded += loadedHandler;
            void closingHandler(object o, CancelEventArgs e)
            {
                if (!dialogWindow.GetDialogViewModel().CanCloseDialog())
                {
                    e.Cancel = true;
                }
            }

            dialogWindow.Closing += closingHandler;
            void closedHandler(object o, EventArgs e)
            {
                dialogWindow.Closed  -= closedHandler;
                dialogWindow.Closing -= closingHandler;
                dialogWindow.GetDialogViewModel().RequestClose -= requestCloseHandler;

                dialogWindow.GetDialogViewModel().OnDialogClosed();

                if (dialogWindow.Result == null)
                {
                    dialogWindow.Result = new DialogResult();
                }

                callback?.Invoke(dialogWindow.Result);

                dialogWindow.DataContext = null;
                dialogWindow.Content     = null;
            }

            dialogWindow.Closed += closedHandler;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates an instance of EventHandler<DialogCloseRequestEventArgs> />
        /// </summary>
        private static EventHandler <DialogCloseRequestEventArgs> CreateHandler <TViewModel>(TViewModel viewModel, IDialogWindow dialog)
            where TViewModel : IDialogRequestClose
        {
            void handler(object sender, DialogCloseRequestEventArgs e)
            {
                // Unsubscribe from the event when event is called
                // once the view is closed, it is not needed anymore
                viewModel.CloseRequested -= handler;

                if (e.DialogResult.HasValue)
                {
                    dialog.DialogResult = e.DialogResult;
                }
                else
                {
                    dialog.Close();
                }
            }

            return(handler);
        }
Exemplo n.º 6
0
 private void CloseDialog(IDialogWindow dialog)
 {
     if (!this.sibilings.Any(product => product.InstanceName.Equals(this.instanceName, StringComparison.OrdinalIgnoreCase)))
     {
         dialog.DialogResult = true;
         dialog.Close();
     }
     else
     {
         this.userMessageService.ShowError(string.Format(
             CultureInfo.CurrentCulture,
             Resources.AddNewProductViewModel_ProductNameDuplicated,
             this.instanceName));
     }
 }
 private void CloseDialog(IDialogWindow dialog)
 {
     dialog.DialogResult = true;
     dialog.Close();
 }
Exemplo n.º 8
0
 private static void CloseDialog(IDialogWindow dialog)
 {
     dialog.DialogResult = true;
     dialog.Close();
 }
 private static void CloseDialog(IDialogWindow dialog)
 {
     // For a TreeViewItem the double-click event bubbles up and fires for every ancestor TreeViewItem as well
     // We only want to handle it once to close the dialog (ignore repeated attempts to close dialog)
     if (dialog != null)
     {
         if (dialog.DialogResult != true)
         {
             dialog.DialogResult = true;
             dialog.Close();
         }
     }
 }