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

Using MEF with an WPF application?

Oct 8, 2009 at 1:38 AM


I am just getting started with a new app in WPF and would like to use MEF (I think).  I am using the mvvm pattern, and I have a component based application.  In particular, since I am just getting started here, I would like to use MEF to either notify all registered viewmodels when an event occurs, or even be able to pass relevant objects around.

I spent some time playing today, but so far had no luck- I was trying to export a property from my MainView, which determines which UserControl is active within the MainView.  Since I am new to this, and trying to do something very simple, I am having a hard time following the examples, to be honest.  They all use MEF it very different ways- for a beginner it is very difficult to identify what is relevant to my application. 

I want a property from MainViewModel to be shared (lets call it CurrentPage) which can be accessed by another ViewModel (AppstartViewModel).  So that when the user does something within the AppstartView.xaml, the proper binding is used to call a method in AppstartViewModel which can then in turn set CurrentPage in MainViewModel.  An alternative would be to use MEF to control the views directly (still based on user input) or even just to pass simple string messages around which the viewmodels can listen for and process accordingly.

Again, Im very new to the IoC stuff so Im open to suggestions as to what I -should- be doing as opposed to what I want to do :)

Is this an appropriate tool to help me with this, and if so, what is the sequence of events I need to do to get something simple like this up and running?

Any help is greatly appreciated!

Oct 8, 2009 at 7:40 PM

You might have a look at the WPF Application Framework (WAF) project. It is a Model-View-ViewModel (MVVM) framework that supports MEF. The ViewModel and Writer sample applications show how to use the MVVM pattern together with MEF.