0
votes

I have a question about MVVM Light in WPF 4.5. It shouldn't require any code. I am just curious what happens when I send a message to trigger a viewmodel to send BACK to the original viewmodel an ICollectionView. Are they now two separate copies, or am I accessing the original that I requested? If I am not, how do you access the original variable so that you don't have 'new' up a second ICollectionView ?

1

1 Answers

1
votes

Let me see if I understand your problem:

You have two ViewModel call VM1 and VM2.

VM1 could listen the messages from VM2 like that:

  Messenger.Default.Register<ICollectionView>(this, HandleCollectionReceived);   
  private void HandleCollectionReceived(ICollectionView collection)
  {
    // do stuff with the collection
  }

Then VM2 can send the original collection to VM1 like that:

Messenger.Default.Send(MyCollectionView);

Or a copy like that:

var MyCopy = new CollectionView(MyCollectionView);
Messenger.Default.Send(MyCopy);

In other words: you choose what you send in the message, thus you choose if you send an original or a copy of your object.