Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Closing. Yes - that's it

Tags:

mvvm

wpf

I love the idea of MVVM but really struggling with the hoop-jumping required for really basic things like getting a value back from a modal dialog or closing a window. I mean...

App.xaml defines StartupUri=MainWindow.xaml.

MainWindow.xaml defines DataContext=MainWindowViewModel.

As per MVVM, View knows about ViewModel but NOT vice versa.

I can't find a (common? logical? straightforward?) way of intercepting the close event. I can use "clever" code blocks like MVVMLight .. but I always end up with either handling an event (messily) or not being able to cancel the close or missing it completely.

I refuse to believe this is so difficult - it must be me falling into another noobie pitfall. Please put me straight!

Thank you again for your time and patience - it is truly appreciated.

like image 872
AndyC Avatar asked Dec 02 '25 06:12

AndyC


1 Answers

This is easily handled via attached properties or a Behavior. I wrote a sample on the Expression Gallery showing how you can use a Behavior to wire this handling up to a command in your VM without using code behind.

like image 70
Reed Copsey Avatar answered Dec 03 '25 20:12

Reed Copsey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!