I would advise you to familiarize yourself with the MVVM messaging system. This is perhaps the easiest approach I have found for this. Here is an example of how it works:
If you have 2 viewing models - 1 for searching customers, another for displaying information about the selected client:
In the first view model, you have a property like this:
public string CustomerID { get { return _customerid; } set { if (_efolderid == value) { return; } var oldValue = _customerid; _customerid = value;
Then, in the second viewing model, you register to receive messages when this value changes from another, for example:
void registerForMessages() { Messenger.Default.Register<PropertyChangedMessage<string>>(this, (pcm) => { if (pcm.PropertyName == "CustomerID") { customerID = pcm.NewValue; AddWorkplanCommand.RaiseCanExecuteChanged(); loadCustomerDetails(); } }); }
Be sure to call the registerForMessages () function in the constructor of the second view model. Another thing that helps is to create a map when you have 4 or more ViewModels in your application. I find it easy to build it in a quick text file in the solution in order to keep track of all the messages and what they are designed to run, and what other view models are logged to receive them.
One of the very nice things about this is that you have 1 view model that sends a change notification, such as the customerID property, and 4 other view modes immediately appear, and they all start downloading the changes themselves.
Ryan from denver
source share