I've been doing a Wpf program for some time now. But when i create a application and create multiple viewmodel. And i need to access a property in a different view model.
So in order to access it. I need each viewmodel to be static.
Then i searched how does view model should be communicating to each other.
Then i found an answer here
https://stackoverflow.com/questions/4892731/wpf-mvvm-how-do-viewmodels-communicate-with-each-other
So i searched for prism aggregator and i found a tutorial
https://www.c-sharpcorner.com/UploadFile/5ffb84/prism-event-aggregator-in-wpf-with-mvvm/
Then i followed it.
just like the tutorial. I added a event class
in the Model folder
And here is the code
namespace MdbMerge.Model
{
public sealed class Event
{
#region Class Properties
internal static Event EventInstance
{
get
{
return eventInstance;
}
}
#endregion
#region Instance Properties
internal IEventAggregator EventAggregator
{
get
{
if (eventAggregator == null)
{
eventAggregator = new EventAggregator();
}
return eventAggregator;
}
}
#endregion
#region Constructors
private Event()
{
}
#endregion
#region Class Fields
private static readonly Event eventInstance = new Event();
#endregion
#region Instance Fields
private IEventAggregator eventAggregator;
#endregion
}
}
but when i set the datacontext of my viewmodel it gives me error
DataContext = new MdbMergeViewModel(MdbMerge.Model.Event.EventInstance.EventAggregator);
It says. MdbMerge does not contain a definition for model.
So how can i solve this?
Why does the Methods inside is not read?
Here is the screenshot of the structure of my program
Thank you.