I have an observableCollection containing several viewModels which are bound to an entity model each. The viewModel additionally contains several calculated text values:
public class SampleViewModel : NotificationObject
{
private Entity _myModel;
public Entity Model
{
get;
private set;
}
public string HasEntries
{
get
{
if(Model.Entries.Count > 0)
return "Model has Entries";
else
return "Model has no Entries";
}
}
How can i now inform the ViewModel and the ObservableCollection in the View that the HasEntries-Property has changed when the model gets updated?
sampleViewModel.Model.Entries.Add(entry);
Edit:
To clarify: I sometimes add an entry to the model by just setting an reference in the entry-entity:
private void addEntry(){
Entry t = new Entry();
t.IDModel = sampleViewModel.Model.ID;
dataAccessLayer.AddEntry(t);
}
All of this happens in the same context and so the object will show up in the sampleViewModel. I just have to find a way to catch this event and notify the viewModel about the newly added object.
I found a pretty easy solution. As it turns out every entity automatically raises a propertyChanged-Event when a property is changed. All i had to do was to bind the PropertyChanged-Event of the Model to the viewModel:
And in my specific case because it is a collection: