예제 #1
0
        /// <summary>
        /// This is called when user clicks X button in dialog title bar</summary>
        /// <param name="sender">Sender of the event</param>
        /// <param name="e">Event args</param>
        protected virtual void OnDialogClosing(object sender, HostClosingEventArgs e)
        {
            var vm = m_viewModel;

            if (!m_closing && vm != null && vm.CancelCommand != null)
            {
                // Catch case where dialog is closed using the close button via windows
                // Feed this through the view model
                if (!vm.CancelCommand.CanExecute(null))
                {
                    // VM has prevented dialog close so cancel the operation
                    e.Cancel = true;
                }
                else
                {
                    try
                    {
                        m_closing = true;
                        vm.CancelCommand.Execute(null);

                        // Only set dialog result if this is a modal dialog
                        //if (ComponentDispatcher.IsThreadModal)
                        //    m_host.DialogResult = e.Cancel;

                        //e.DialogResult = e.Cancel;
                    }
                    finally
                    {
                        m_closing = false;
                    }
                }
            }

            // Removed this as the DataContext is required in overriding methods
            if (!e.Cancel)
            {
                // DAN: Workaround as for some reason even after dialog is closed
                // The command manager keeps querying the commands in the data model!
                DataContext = null;
            }
        }
예제 #2
0
        /// <summary>
        /// Event raised when the dialog is being closed.</summary>
        /// <param name="e">A <see cref="T:System.ComponentModel.CancelEventArgs" /> that contains the event data.</param>
        protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);

            if (!e.Cancel)
            {
                var args = new HostClosingEventArgs {
                    DialogResult = DialogResult
                };
                DialogClosing.Raise(this, args);

                e.Cancel = args.Cancel;

                // Prevent main application disappearing behind other windows:
                // http://stackoverflow.com/questions/13209526/main-window-disappears-behind-other-applications-windows-after-a-sub-window-use
                if (!e.Cancel && Owner != null)
                {
                    Owner.Focus();
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Request that the dialog close with given dialog result.
        /// DialogClosing event is raised, allowing subscribers the chance to cancel.
        /// </summary>
        /// <param name="dialogResult">The desired dialog result to close with</param>
        /// <exception cref="System.InvalidOperationException">Owner is null</exception>
        public void RequestClose(bool?dialogResult)
        {
            var owner = Owner as IDialogSite;

            if (owner == null)
            {
                throw new InvalidOperationException("");
            }

            var args = new HostClosingEventArgs()
            {
                DialogResult = dialogResult
            };

            DialogClosing.Raise(this, args);

            if (!args.Cancel)
            {
                owner.HideSite();
                owner.Site.Children.Remove(m_dialogContent);
                m_dialogResult   = args.DialogResult;
                m_frame.Continue = false;
            }
        }
예제 #4
0
        /// <summary>
        /// Event raised when the dialog is being closed.</summary>
        /// <param name="e">A <see cref="T:System.ComponentModel.CancelEventArgs" /> that contains the event data.</param>
        protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);

            if (!e.Cancel)
            {
                var args = new HostClosingEventArgs { DialogResult = DialogResult };
                DialogClosing.Raise(this, args);

                e.Cancel = args.Cancel;

                // Prevent main application disappearing behind other windows:
                // http://stackoverflow.com/questions/13209526/main-window-disappears-behind-other-applications-windows-after-a-sub-window-use
                if (!e.Cancel && Owner != null)
                    Owner.Focus();
            }
        }
예제 #5
0
        /// <summary>
        /// This is called when user clicks X button in dialog title bar</summary>
        /// <param name="sender">Sender of the event</param>
        /// <param name="e">Event args</param>
        protected virtual void OnDialogClosing(object sender, HostClosingEventArgs e)
        {
            var vm = m_viewModel;

            if (!m_closing && vm != null && vm.CancelCommand != null)
            {
                // Catch case where dialog is closed using the close button via windows
                // Feed this through the view model
                if (!vm.CancelCommand.CanExecute(null))
                {
                    // VM has prevented dialog close so cancel the operation
                    e.Cancel = true;
                }
                else
                {
                    try
                    {
                        m_closing = true;
                        vm.CancelCommand.Execute(null);

                        // Only set dialog result if this is a modal dialog
                        //if (ComponentDispatcher.IsThreadModal)
                        //    m_host.DialogResult = e.Cancel;

                        //e.DialogResult = e.Cancel;
                    }
                    finally
                    {
                        m_closing = false;
                    }
                }
            }

            // Removed this as the DataContext is required in overriding methods
            if (!e.Cancel)
            {
                // DAN: Workaround as for some reason even after dialog is closed
                // The command manager keeps querying the commands in the data model!
                DataContext = null;
            }
        }
예제 #6
0
        /// <summary>
        /// Request that the dialog close with given dialog result.
        /// DialogClosing event is raised, allowing subscribers the chance to cancel.
        /// </summary>
        /// <param name="dialogResult">The desired dialog result to close with</param>
        /// <exception cref="System.InvalidOperationException">Owner is null</exception>
        public void RequestClose(bool? dialogResult)
        {
            var owner = Owner as IDialogSite;
            if (owner == null)
                throw new InvalidOperationException("");

            var args = new HostClosingEventArgs() { DialogResult = dialogResult };
            DialogClosing.Raise(this, args);

            if (!args.Cancel)
            {
                owner.HideSite();
                owner.Site.Children.Remove(m_dialogContent);
                m_dialogResult = args.DialogResult;
                m_frame.Continue = false;
            }
        }