Can we close WPF window after InitializeComponent() if any validation fails? I am validating that the file exist on window load, if the file doesn’t exist, then how to close the window before it loads?
Can we close WPF window after InitializeComponent() if any validation fails? I am validating
Share
I would recommend a different approach.
I think this should not be decided by the window itself, but rather by some business rules validation object.
With WPF it comes natural to using the MVVM pattern so the validation might be done the the ViewModel or a dedication validation class. The should make the decision if a window should be opened at all.
This approach would spare from instancing, opening, and eventually closing a completely unneeded window if the opening condiotions are not met.