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

Dynamic View/ViewModel Routing and advanced Region management.

Nov 19, 2010 at 6:21 AM
Edited Nov 19, 2010 at 6:22 AM

Hi Jeremy, I have 3 questions:

Our architecture heavily depends on the modules contained in the downloadable xaps,

And all our views, viewmodels and resources live in the separate xaps and viewmodel can be bound to a different view during the execution and vice versa depending on the out custom xml configuration :

 <module name="MyJounceViewModels.xap" />

            <module name="MyJounceViews.xap" />

           

 

            <region name="QListRegion">

                <view name="MyJounceViews.QueusListPage" viewModel="QListViewModel"></view>

 

            </region>

 

  1. Threfore we need an ability to create and add routes dynamically.
    In the meantime the only direct way to merry view and the viewmodel using Jounce is to [export] the route. What if we want to redefine the viewmodel in the middle of the application execution ?
    I had to implement a little dirty workaround for this:


     

        [Import]

        public IViewModelRouter ViewModelRouter { get; set; }
...

                            var oldRoutes = ((ViewModelRouter)ViewModelRouter).Routes;

 

                            ViewModelRoute[] newRoute = new ViewModelRoute[oldRoutes.Length + 1];

                            oldRoutes.CopyTo(newRoute, 0);

                            newRoute[oldRoutes.Length] = ViewModelRoute.Create(view.ViewModel, view.Name);

                            ((ViewModelRouter)ViewModelRouter).Routes = newRoute;

... not very clean, right ?
Is there way you could probably  add route to the Routes array within the ViewModelRoute.Create method ?
    

 2. In the same way as we redefine the views for the viewmodels we want to specify the region for the view dynamically, we need more freedom than

[ExportViewToRegion(CIRCLE,LocalRegions.APP_REGION)], we want to be able to specify the region for the view in the middle of the application execution.

I am trying to do this:

        [Import]

        public IRegionManager RegionManager { get; set; }

        [ImportMany(AllowRecomposition = true)]

        public Lazy<UserControl, IExportAsViewMetadata>[] Views { get; set; }


.…

var adapter = (from r in ((RegionManager)RegionManager).RegionAdapters

         where r.Value.GetType() == typeof(GenericRegion) select r).FirstOrDefault();

var viewControl = Views.Where(v => v.Value.ToString() == view.Name).FirstOrDefault();

var control = viewControl.Value;

 

adapter.Value.AddView(control, view.Name, region.Name);

adapter.Value.ActivateControl(view.Name, region.Name);

Where GenericRegion is my custom Region adapter.
I believe your Jounce could give us the cleaner way of doing this.




3. We need to know when ALL xaps have loaded because from Deployment.Catalog.Changed does not tell us enough.

Coordinator
Nov 29, 2010 at 12:58 PM

Yes, I'll add the direct configuration as a feature request.

Will look into the region addition as well.

For the xap loaded, that is something that I would say a module would need to track. I am considering sending an event aggregator message on module load so you can register to listen and keep track.

Thanks!