This project is read-only.

View Reference in View Model

Oct 7, 2012 at 6:12 PM

Please excuse if I sound stupid and ignorant.

While creating Modal Dialogs I can see the View references in View model.


var modalResult = Singletons.NavigationService.ShowModal<SendMailView, string>(navigationInfo)

Here, SendMailView is a xaml view. Isn't this against the MVVM guideline?


Oct 8, 2012 at 11:36 PM
Edited Oct 8, 2012 at 11:47 PM


Don't worry, your question makes sense and moreover, it is an interesting one.

From your example, "SendMailView" is actually a xaml view as you stated.

However in this context, it is not an instance of a view and so the view model instance do not have reference to a view instance.

Here, it is rather used as a kind of identfier to use when the "ShowModal" method will look for an actual view that will be bound to the given view model.

I could have implemented the "ShowModal" method with the signature : ShowModal (string viewIndetifier, NavigationInfo navigationInfo) and the strong reference to the view type has disappeared while this method keeps exactly the same capability.

I prefered however the current implementation because it is simpler in term of implementation.  I plan to improve the view lookup in next versions (probably by using MEF and perhaps a design by convention approach or a better mechanism, I'm on it :))

Does that make sense ?


Oct 9, 2012 at 7:25 AM

What I understand is the VM would make use of some identifier which will be parsed at the container level to get the View element.

Makes sense. I would wait for the next release of Lakana! :)



Oct 9, 2012 at 12:12 PM

Exactly !

Web applications use URLs to find and identify the correct view to display, Lakana uses the type of the view (not an instance of it) to achieve the same behavior.

I do agree however that it is not the best solution, but as I said, I will improve it in future releases.