We have a parent class which has a collection of children. Both classes support change notification using Template10. Change notification works within each class (ie when we update a property within the same class) as below, but we are unable to trigger change notification on the parent from the child.
public class ParentViewModel : ViewModelBase
{
public string ParentString { get }
public decimal? Net { get { return Total / (1 + TaxRate / 100); } }
public decimal? Tax { get { return Total - Net; } }
decimal? _Total = default(decimal?);
public decimal? Total
{
get
{
return _Total;
}
set
{
Set(ref _Total, value);
RaisePropertyChanged(nameof(Net));
RaisePropertyChanged(nameof(Tax));
}
}
public ObservableCollection<ChildViewModel> MyChildren { get; set; }
We find we are able to use RaisePropertyChanged
in ParentViewModel
to fire
Net { get { return Total / (1 + TaxRate / 100); } }
and
Tax { get { return Total - Net; } }
On ChildViewModel
we have ChildString
. We want to notify ParentString
of changes to ChildString
.
public class ChildViewModel : ViewModelBase
{
ParentViewModel MyParent { get; set; }
string _ChildString = default(string);
public string ChildString
{
get
{
return _ChildString;
}
set
{
Set(ref _ChildString, value);
RaisePropertyChanged(nameof(this.MyParent.ParentString));
}
}
However ParentString
is not updating. How do we force ParentString
to update when ChildString
updates?