tags:

views:

109

answers:

2

i want to split my views project into sereveral modules. i wanna have a main project that willl have ref to all modules and this main project will generate the view from the modules.

my question is how can i bind all the styles from the application to the other modules?

will it automatically recognize them?

and how will the view model templates will be located? cause now they r in a resource dictionary that i merge in the app.xaml

where shpuld i put them (i want them to be in their module project), how can i load thos resources?

+1  A: 

What you want is easily achieved if you use Prism: http://www.codeplex.com/CompositeWPF

There's plenty of samples to get you started there.

The only question you ask that isn't answered by Prism is the ResourceDictionaries, but there are several ways to get around that, but I think this is the best way: http://stackoverflow.com/questions/1172171/composite-wpf-prism-module-resource-data-templates

The first answer should get you there. You'll lose a little design time support in your modules, but everything should come together correctly at runtime this way.

Anderson Imes
+1 for the link - an interesting method.
Scott Whitlock
+2  A: 

Hello, good question. As Anderson Imes said, you can use Composite WPF, but there is another simpler option that's recently available if you make use of the Managed Extensibility Framework (MEF). There is another question I asked about how to do exactly what you're talking about using MEF. Basically it uses the extensibility features of MEF to make the application resources extensible, and then your modules "extend" the application resources with their DataTemplates (Views). Then you just add your ViewModel to the GUI wherever you want, and WPF takes care of applying your View to it. I've been building an application on this model and it's working really well.

The benefit of using this method is that your app.xaml file doesn't have to "know" about all your View modules, and you're free to slice and dice your application any way you like (I prefer to segment it by feature, then by layer).

Scott Whitlock
I disagree that the App.xaml "knows" about the Module's views... we're just allowing the module to insert its own resources into the App.xaml. Does MEF get around this limitation somehow (allow modules/plugins to style their controls without explicitly referencing the resource dictionary in your view's resources)?
Anderson Imes
@Anderson Imes - Yes. If you have an App.xaml with a merged dictionary of other resource dictionaries, then you have to call out the other dictionaries by name (at compile time). However, if you follow the method in the linked question, then the modules and plugins can insert their resource dictionaries at runtime.
Scott Whitlock
it's still only going to merge them all at runtime when MEF loads its plugins. The thing you gain here is a declarative vs. imperative model for inserting resource dictionaries into the app. There's nothing compile time about this approach. That said, its actually pretty nice.
Anderson Imes
@Anderson Imes - I believe you're comparing Prism with the MEF approach I'm referencing. Sorry about that... I was confused. I must admit I'm not terribly knowledgeable about Prism. When I was talking about the "benefit" of this method, I was only comparing it to the method posed in the question ("now they r in a resource dictionary that I merge in with app.xaml").
Scott Whitlock
Yeah, that's definitely nice. I have to go through a little bit more trouble to get this effect in Prism.
Anderson Imes
both answers r grate 10x allot.
Chen Kinnrot