I want to pass SecondViewModel SecondProperty value to ViewModel myProperty and show the value on TextBlock. i want the codi
From your comment, assuming that ViewModel
holds a collection of SecondViewModel
items, you need to set the PropertyChangedEvent
for each instance of SecondViewModel
to trigger ViewModel.myProperty
to refresh. e.g. ...
public class ViewModel
{
private List _secondViewModels = new List();
public IEnumerable SecondViewModels => _secondViewModels;
public int myProperty => _secondViewModels.Sum(vm => vm.SecondProperty);
public void AddSecondViewModel(SecondViewModel vm)
{
_secondViewModels.Add(vm);
vm.PropertyChanged += (s, e) => OnPropertyChanged(nameof(myProperty));
OnPropertyChanged(nameof(myProperty));
}
}
As an aside, you should never call OnPropertyChanged()
with a "magic string" - use nameof()
instead.