I have a window, and its datacontext is a viewmodel. now, outside the scope of the vm and window(view), i have a method that will be called. the method needs to show the window and let the user change some things, then when the user is done, the window needs to close and the method continue. tricky thing is, i have buttons on the window bound to commands in the viewmodel. these commands fire events like 'userCancelled' and 'userOked'. so i want to catch these events to know when to close the window and continue with the method.
on the window if i use ShowDialog, the events aren't caught (i'm assuming because the thread is tied up waiting on the dialog to close). But if i use Show, the method rolls on. i need it to wait. i've tried Thread.Sleep until some boolean value is switched on, but that ties up the thread too and makes the window unusable (using .Show()).
I've tried making a backgroundWorker, but i still run into the same problem.
i understand i could use codebehind on the buttons, but for the OK button, the viewModel has to verify that its state is valid. having the view consult with the viewmodel defeats the point of MVVM's loose coupling style, right?
I'm learning WPF and MVVM all on my own, and i want to do it right and stick to good design principals where practical. how should i do this? what am i doing wrong? thanks.