Dialog event

Is there a way to have a BeforeClose Event on a dialog?

This should be useful for validating inputs or records before the dialog is closed and preventing its closure in case of invalidation.

Sure, buttons could achieve it, but I want to have it more fluent, the way modern UIs handle this, without clicking a save or ok button