This project has moved. For the latest updates, please go here.

How to use ViewModelLocator in both app project and class library project ?

Aug 1, 2012 at 2:16 AM

I'm using mvvmlight toolkit to develop my Windows 8 app.

For modulize and team work, I have to seperate my solution to different projects which contains app project and other class libray projects. App project basacilly just provide a shell. All Views are in class library projects.

ViewModalocator is originally defined at App.xaml in app project. But I also want to use mvvm pattern with mvvm light toolkit in class library project, because all views are there. So I need ViewModelLocator in class lib. Here are situations I met.

(1) If the key of ViewModelLocator is the same in both app project and class library project, both design time and run time of ViewModelLocator in class library didn't work. Even constructor of ViewModelLocator in class library won't be called. I took some time to figure out that this behavior is the same in wp7. Meaning only App.xaml in app project would be used, others not.
(2) Based on (1) . If I don't define ViewModelLocaotr in class libray project, design time won't work in class library project and this is not what I want.  At last I find out if I defined a different key for ViewModelLocator in class libray project and add this key in app project, both design time and run time would work.

Although this seems to be solved, there's something wrong and I don't think its a right way to solve this situatino. Because if I provide this class libray assembly to someone doesn't know the whole picture. How will he know adding a specific key in his App.xaml  when he using this class library ?

Please give me some advices ?  or there're some missunderstanding usage please let me know.

Thanks for your time.