2

Possible Duplicate:
WPF MVVM Newbie - how should the ViewModel close the form?

So I have a window and the user presses a button. Since I am using MVVM this results in a command firing in my View Model.

At this point my command spins up a background worker to do something interesting. The View is merrily showing a progress bar. The thread complete event then fires in the View Model.

The desired behaviour is when the background thread terminates, the window should close.

So for the life of me, I cannot figure out how to get the thread complete code to close the window without taking a reference to the View in the View Model (which as we all know is akin to killing puppies).

2
  • @Will: you're welcome, although now I have to put a bounty on that question because Nir's flippant answer is so unsatisfying ;)
    – user7116
    Nov 16, 2011 at 13:30
  • @sixlettervariables: If you do a simple search, this question has been asked a number of different times and answered a number of different ways. I know I've answered a version of this in the past. The correct answer is always the same--Orthodox? Use an adapter or behavior or some other abstracted communication method to inform the form to take a hike. Otherwise, grab your reference and be done. No matter what, there isn't a MVVM equivalent of the 10 Commandments, so you can do whatever makes you feel better, including coveting thy neighbor's code.
    – user1228
    Nov 16, 2011 at 13:47

1 Answer 1

2

As far as the progress from your worker is getting into the view (I assume this is done with events the view handles) it should not be so complicated to define a WorkerFinished event in your view model the view also handles.

Not the answer you're looking for? Browse other questions tagged or ask your own question.