I have an observable collection property that holds some instances of a custom class and a string property that outputs the sum of some data in the observable collection property. Like this...
public ObservableCollection<MyClass> MyClasses
{
get
{
return _myClasses;
}
set
{
_myClasses = value;
OnPropertyChanged("MyClasses");
// I thought the following might work but it doesn't seem to
OnPropertyChanged("TotalTime");
}
}
public string TotalTime
{
get
{
int totalTime = 0;
foreach (MyClass myClass in MyClasses)
{
totalTime += myClass.Timespan;
}
return TimeSpan.FromMinutes(totalTime).ToString(@"h\:mm\:ss");
}
}
As elements are added/removed from MyClasses I have a TextBlock
that I want to bind the Text property to TotalTime
, but it is not working.
Any ideas or tricks to make this work?