Yesterday i ask here how does view model communicate it each other. Because the design of my program is. A viewmodel contains a property. Example a property named DirectoryPath
and in the other View model i want to access the value of the DirectoryPath
And below is the link
Prism Event Aggregator - method cannot be read
Then another problem comes in. The comment says. I'm doing it wrong.
Let's say I have a textbox.
Then i want to create a DirectoryPath
string property which will be bind in the text property. Then where should i put this property?
And how can i access this? In my viewmodel I have a command. How can i set the text of the DirectoryPath
when a user click a button?
All this month i spent doing MVVM and WPF is wrong? And i want to fix this.
Sample code of my ViewModel
class ViewModel : INotifyPropertyChanged
{
private string _DirectoryPath;
public string DirectoryPath
{
get { return _DirectoryPath; }
set
{
_DirectoryPath = value;
OnPropertyChanged("DirectoryPath");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string name)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
}