Call view method from viewmodel

May 27, 2012 at 9:57 PM


I came to a point where normal binding won't work for me. I have a third party control which offers two methods restoreLayoutFromXML/saveLayoutToXML. There is no direct way from the control to use it it mvvm style.

I thought about some solutions, but I can't decide what is the best in thinking of mvvm:

1) The simplest way: Add one event to the VM, register a handler in the view and pass the delegate.

2) Use an IView interface

3) Attached behavior


What way would you go?

May 28, 2012 at 8:45 AM

I would go for 1. It might seem dirty, but it is still clean (view model not referencing the view) and easy to understand for other developers that read the code.

May 28, 2012 at 10:45 AM

Thanks, that was my favorite.