I think I don’t see where this unexpected behavior is.
If you designated it as a button Canceland invoke .ShowDialog(), then pressing the button will close the window.
You added your own call to Close()and canceled the close, so both calls are made and the event is incremented at the same time.
, , IsCancel IsDefault XAML. .