This project is read-only.

ViewModelLocator Resolves Multiple Times (SL4)

Apr 14, 2011 at 7:36 PM


If you put a Debug.WriteLine(...) in the constructor of a ViewModel (e.g. MyViewModel) which is resolved via the ViewModelLocator it gets resolved multiple times in Silverlight 4 and only once in WPF 4. I would have expected it to be resolves only once ever...

Can someone please tell me why?  I don't believe it is an issue caused by the ViewModelLocator but rather due to some behavior of Silverlight.

This is a pain for me because do all my creation of commands in the constructor.  Any suggestion on how to resolve this would be much appreciated!

PS This applies to samples on this project too, not st my code. 

Apr 14, 2011 at 10:17 PM


John Papa (the Sr. Tech Evangelist for SL at MS) has some thoughts on doing that with a value converter instead.

More info here:

For me, it doesn't really affect me because it doesn't really hurt me to construct 6.  They get garbage collected. It is, indeed, irritating, though.


Apr 15, 2011 at 6:12 AM

Hi Brian,

Ok, great you are aware of this it's not just me going insane)!

Thanks for the links - will follow those up.