My application creates a number of child Views using a variant of the famous IDialogService. I now have a requirement to enable shutting down these Views on a programmatic basis, when a specific event or set of events occurs.
Firstly, how best should I expose the Views' Close method, bearing in mind that
So far, I have a mixture of attached behaviours to hook into the Closing event to handle cleaning up and an Action on the ViewModel like
vm.OnCloseAction = ()=> view.Close();
to handle actually closing the View from a ViewModel.
This doesn't feel particularly elegant to me, though. Does anyone have any other ideas or alternative approaches?
One idea would be to use whatever Messaging framework you're using (like the Messenger in MVVM Light, which is what I use), set up a Closing message (or something like that) and have anything that needs to do something on close Register for that Closing message.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With