h1

Hello,

I'm trying out Model-View-ViewModel. I really like the results. I have a unit testable ViewModel (nice!). But as I do more examples, I find that there are something I can't do and still keep the viewModel ignorant of the view.

Let's say in response to button click the application has to open a window:

I have encapsulated the code that responds to the button click in a command, the command is owned by the ViewModel. So far so good. Everything is testable. But now I need to pop-open a window...in other words my viewmodel needs to know how to pop open a navigationwindow (I'm using pages). Which would make my view model hard to test How can I get around this kind of problem.

Thanks

Houman



Re: Windows Presentation Foundation (WPF) How do you do it in the Model-View-ViewModel (Part 1:-)

SerialSeb

Old question, but I didn't see it before and it's a shame it's not been answered.

The way I go about it is to implement an interface on my view (my XAML code behind), with viewmodel oriented method names. So your MainPage.xaml would implement IMainView, which has a method called ShowThatStuff().

You then implement your view-specific windowing code in your view, expose it as an interface. At unit test time, you can now implement a simple class that implement the interface and check that everything was called properly.






Re: Windows Presentation Foundation (WPF) How do you do it in the Model-View-ViewModel (Part 1:-)

Houman b

Thanks, what I ended up doing is that I implemented a delegate that I pass into the view model to pop-open a window. I'll try your way as well. And post my findings.