0
votes

Can somebody guide me what should be the design if I want to create a MVVM application in Prism(Silverlight) using MEF( I am not sure how to import or export ViewModel using MEF).

I saw few article which are binding ViewModel with View using DataContext(either in XAML or codebehind of View).

And I saw few guys who are having IView & IViewModel interface & both are having reference variable of each other.

And at some places the guidelines says ViewModel should never be referring to View.

It would be nice if somebody can provide me code snippet.

2
A simple "code snippet" is not going to be enough to explain what you need. As mentioned below, your best bet is to read up on the Prism docs, and check out the different sample applications they include. The StockTrader application will show you both MEF and MVVM principles.Thelonias

2 Answers

1
votes

Have you read the Prism documentation? They have a section on Implementing the MVVM Pattern which discusses different techniques for wiring up the viewmodel and view.

You could also implement a composite application with an MVVM framework such as Caliburn.Micro which uses conventions for viewmodel/view binding.

0
votes

I would bind the DataContext using setter injection in the code behind. Both the view and the view model are created by MEF.

[Import]
private MyViewModelClass ViewModel
{
    get { return this.DataContext as MyViewModelClass; }
    set { this.DataContext = value; }
}