From what I (thought to) understand is that implementing INotifyPropertyChanged within the ModelView, allows to raise the PropertyChanged event in case a property has been modified.
That way the View should get to be notified that the underlying property has changed and hence the UI should fetch the new changes.
Did I get the theory right?
The problem I face is that I have an Infragistics DataGrid bound to a ViewModel. As soon as I change a date Value, I can see how the property on the ViewModel is set correctly and the event is raised. But I haven't subscribed from outside to this event though, how does the UI get notified?
I am asking this because I think the UI is not notofied at all. I have placed a second textbox that is binding thourgh the ViewModel to the same underlying Model property. However if I modify that property with the DataGrid, the TextBox (Mode=OneWay) is not automatically updated.
I actually make use of MVVM-Light Frame work and use ViewModelBase instead of INotifyPropertyChanged and do a RaisePropertyChanged(...). But the result should be similar.
Do I have to subscribe the TextBox manually to that Event somehow?
Edit: I have solved the problem, but dont grasp exactly why this is happening. Before answering the Question I need to explain a bit more about the architecture. The Datgrid is bound to propertyA in ViewModelA that returns an ObservableCollection<ViewModelB>.
ViewModelB actually contains all the properties that the Grid should be displaying. All these properties fire in their Setters naturally an OnProperyChanged.
The TextBox was bound to PropertyB, that lives also within ViewModelA. But it returns directly a string, so the underlying getter of PerpertyB returns this:
_cashflowInputs[0].ProjectedDate.ToString();
However if I dont bind the TextBox to this propertyB, but bind it to PropertyA as well, it works:
Its weird. I was expecting it to work the same way. Both Properties live on the same ViewModel and access the same private ObservableCollection<ViewModelB>
, why should it matter?
public ObservableCollection<ViewModelB> PropertyA
{
get { return _cashflowInputs;}
}
public string PropertyB
{
get { return _cashflowInputs[0].ProjectedDate.ToString(); }
}
Kave