I'm writing a WPF/MVVM application using Prism/Unity. I'm having issues on how to transfer data from one usercontrol to another when navigating a region.
I have a region
This is populated by a user control("ContactsList") solely containing a grid, this grid is bound by ItemsSource & SelectedItem.
I want to navigate to ContractEdit and pass the Contact bound to SelectedItem.
LocalRegionManager.RequestNavigate(ContactRegions.MainRegion, ContactsUri.ContactsEdit);
I can pass a single value in he Datacontext or the Uri but I don't want to have to go back to the Database to get the data when I already have the whole Item in the list view model.
How can I pass a whole object from the list usercontrol to the edit control?
Thanks in advance.
Conclusion
I added the EventAggregator
public ListViewModel(IEventAggregator eventAggregator, IRegionManager regionManager)
{
_eventAggregator = eventAggregator;
_regionManager = regionManager;
}
Published the even when navigating
private void OnSendData()
{
_regionManager.RequestNavigate(ShellRegions.LeftRegion, ModuleAUris.Edit);
_eventAggregator.GetEvent<UserEvent>().Publish(_selectedItem);
}
Then subscribed to the even to get the object.
public EditViewModel(IEventAggregator eventAggregator, IRegionManager regionManager)
{
_regionManager = regionManager;
_eventAggregator = eventAggregator;
BackCommand = new DelegateCommand(OnBack);
_eventAggregator.GetEvent<UserEvent>().Subscribe((e) => UserEntity = e);
}