Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
MVVM stumbling block...
Message
De
11/06/2010 12:30:21
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Windows Presentation Foundation (WPF)
Titre:
MVVM stumbling block...
Versions des environnements
Environment:
C# 3.0
Divers
Thread ID:
01468562
Message ID:
01468562
Vues:
112
Hi,

I'm working on a WPF app using EF and the MVVM pattern. It's also using Prism but I fiddled with that so that designers can specify the ViewModel they wish to use in the XAML markup for the View.

This worked fine : When the View was instantiated it found the ViewModel which in turn pulled in the data from SQL. The EF connection settings were stored at the Application level.

Now I need to access more than one DB at the same time. They will have identical structures but be on different servers so the only difference as far as the ViewModel/Model is concerned will be the connection settings.

For the sake of argument assume there are two Frames on a form. Any view instantiated in Frame A should use DB1 ; any view in Frame B should use DB2. My basic problem is that at the point where the View begins loading the ViewModel the View itself is not yet 'sited' so I can't determine which Frame it is destined for and thus can't feed to correct DB connection to the ViewModel.

The only solution I've come up with so far is to wire the Loaded event to the ViewModel and have that walk the tree to find the containing Frame but that feels like a kludge (and breaks MVVM rules). Can anyone think of a more elegant way of doing this or must I rethink the design entirely :-{
Répondre
Fil
Voir

Click here to load this message in the networking platform