Kristian Vukusic
Kristian Vukusic

Reputation: 3324

MVVM Referencing Assemblies

I am implementing the MVVM pattern in the application I'm working on, and I have 3 seperated assemblies in my solution, the Model, View, and ViewModel. The ViewModel has a reference to the Model, and the View has a reference to the ViewModel. In my Model I have a class Event, and in the ViewModel I create an ObservableCollection<Event>. The problem is when I try to set this collection as the DataContext of a ListView in the View. I get this error:

error CS0012: The type 'Model.Event' is defined in an assembly that is not referenced. You must add a reference to assembly 'Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

I want to have the app decoupled as much as possible, and this is not decoupling my app. I know that when I add a reference of the Model to my View, then I would not get the error, but I do not want my View having a Model Reference. How to make this working?

Upvotes: 1

Views: 190

Answers (1)

Big Daddy
Big Daddy

Reputation: 5234

There's nothing wrong with having your view assembly reference the model assembly. I think it's common practice and the only way your going to get your models to display in your view. Assuming you're binding to your view-model's ObservableCollection from your view's xaml (not code-behind), I don't see tightly coupled assemblies here.

Upvotes: 1

Related Questions