This project has moved and is read-only. For the latest updates, please go here.

Non shared views usage

Sep 29, 2011 at 12:22 PM
Edited Sep 29, 2011 at 12:26 PM

Hi Jeremy,

Sorry for being novice on Non shared views. what is the purpose it solves in real world applications. From your example of binding a usercontrol to a list box through NonSharedViews,

when i can directly bind a usercontrol(ContactsView usercontrol in ur quickstart examples) to the ItemTemplate of ListBox and bind the Model object directly to display the content, why should i bind list of viewmodels, which inturn searches for view and creates new instances of views and bind that to the ListBox using JounceViewConverter.

 instead of this

 <ListBox ItemsSource="{Binding ViewModels}">
                    <ContentControl Content="{Binding Converter={StaticResource ViewConverter}}"/>

using this
<ListBox ItemsSource="{Binding Contacts}">
                    <ContactsView DataContext={Binding}/>

Please let me know where it will be useful to use Nonshared views in real world application that you have encounterd and got benefit of Nonsharedviews


Sep 29, 2011 at 1:18 PM

When you take the first option, Jounce wires in additional constructs - for example, it will set the delegates for the visual state manager on the view model so that in the view model, you are able to transition states and have those impact the view. You can also take advantage of automatically calling activate/deactive on the view model whenever the view is loaded/unloaded. In the second example, you can use the view model bindings, but you don't get that additional functionality. If all you are doing is binding properties, you are fine. If you want commands and other constructs at the item detail level, however, you will lose that or have to resort to hacks to wire it up ... that's why the converter allows you to simply take a view model that is cast to the detail item and spin up a fully wired view.

Sep 29, 2011 at 3:07 PM

Thanks jeremy.

One issue(May be a deliberate stuff you would have planted),  i could see is

The extention method for contact object Needs a ContactViewModel reference in ToViewModel() method. when i am trying to wire in a ViewModel from a different XAP, i dont get a way to Wire in the Source property as it will not be available. I Changed ContactViewModel to IViewModel in extentionmethods, MainViewModel and i could able to wire in the controls, but i could not able to set a Source property. obvisously it will not be available as part of IViewModel.

1) Do i need to add a Source property to IViewModel, ViewModel base to assign the binding array collection value to individual Nonshared views,

2) is there any way to pass the binding Contact object to the Nonshared View/ViewModel to do further manipulations or anyway to set the datacontext of the binding view to the incoming  Model(Contact object here) class 

Your suggestions pls.

Sep 29, 2011 at 3:12 PM

Not sure I fully understand but in general you can expose a list of IViewModel for view models in a separate XAP, and then the bindings will realize the implementation at run time.