protected override void OnAttached()
        {
            var associatedObject = AssociatedObject;

            if (associatedObject == null)
            {
                throw new InvalidOperationException();
            }

            base.OnAttached();
            associatedObject.Closing += (sender, e) =>
            {
                if (e == null)
                {
                    throw new ArgumentNullException(nameof(e));
                }

                if (CanClose)
                {
                    return;
                }
                if (CloseCanceledCallbackCommand != null && CloseCanceledCallbackCommand.CanExecute(null))
                {
                    CloseCanceledCallbackCommand.Execute(null);
                }

                if (CloseCanceledCallbackMethodTarget != null && CloseCanceledCallbackMethodName != null)
                {
                    _callbackMethod.Invoke(CloseCanceledCallbackMethodTarget, CloseCanceledCallbackMethodName);
                }

                e.Cancel = !this.CanClose;
            };
        }
예제 #2
0
        protected override void OnAttached()
        {
            base.OnAttached();
            AssociatedObject.Closing += (sender, e) =>
            {
                if (!CanClose)
                {
                    if (CloseCanceledCallbackCommand != null && CloseCanceledCallbackCommand.CanExecute(null))
                    {
                        CloseCanceledCallbackCommand.Execute(null);
                    }

                    if (CloseCanceledCallbackMethodTarget != null && CloseCanceledCallbackMethodName != null)
                    {
                        _callbackMethod.Invoke(CloseCanceledCallbackMethodTarget, CloseCanceledCallbackMethodName);
                    }

                    e.Cancel = true;
                }
            };
        }