Bind.Model usage needs explaining

Aug 3, 2010 at 7:16 PM

I'm not sure if I'm missing something here, but if I start with a SL4 Business application project template, I can create a dedicated Bootstrapper<T> that uses Unity to resolve instances. As adviced by Rob, I want to use View-first binding for the individual pages. But the usage of Bind.Model is a bit unclear. Considering a Search.xml navigation page, I can do something like this (namespaces left out for brevity).

<navigation:Page micro:Bind.Model="searchModel">


But then it will attempt to use Unity to resolve the key 'searchModel' into an object. But Unity cannot resolve a key without specifying the explicit type. Are there any other ways of getting my view to bind to the VM that is build up by Unity?

Aug 3, 2010 at 7:28 PM

If you are building a SL4 application using the Navigation Framework, have a look at the new pieces I added to the WP7 version around navigation. They should be easily adaptable to the SL4 Nav framework. Regarding unity, if you change your bootstrapper to pass typeof(object) for queries based on key without type that should fix the issue. Like this:

return _container.Resolve(serviceType ?? typeof(object), key);

Aug 4, 2010 at 7:13 AM

Hi Rob,

I tried that, but it didn't work until I changed the registration into this:

container.RegisterType(typeof(object), typeof(SearchViewModel), "searchViewModel");

You have to use typeof(object) explicitly.