views:

41

answers:

1

Guys,

I was wondering if there's any way i could handle when a collection changes and, after that, display a message to the user.

As im using MVVM, i dont have any references to the model inside the view project, so i couldn't do

MyCollection col = InstanceOfViewModel.Read();

Since View doesn't know anything about "MyCollection", and i dont want to test the method itself inside a if, like the code above:

if(InstanceOfViewModel.Read().Count == 0)

So i thought about Commands. I'm already using one to handle my saving & updating conditions (instead of tons of if's). But now im trapped. I cant figure out what should i do/use cause, ObservableCollections exposes one event, CollectionChanged.

One solution could be: make the viewmodel subscribe to this event, and when it happens, check if the count is equals 0, if true, show to user: "Your search didnt retrieved any rows" or anything else. But i dont like to use MESSAGEBOXES in a viewmodel, messages and any kind of User Interactivity im trying to delegate to the View(s)

But i would like to know if i CAN do it using COMMANDS, or if im getting too complicated in a thing that is relatively easy to implement.

Waiting for answers and thanks in advance!

A: 

if your collection is in a viewmodel and you are using the onPropertyChanged...anytime your entire collection changes(not the individual items) it would fire onPropertychanged which you could watch for in your onPropertyChanged method...Maybe I am not understandig your code structure...

ecathell
dep, yeah my model classes implements INotifyPropertyChanged, but i didnt noticed it would fire for the entire collection itself as well. Thanks, ill give it a try.
Edward