Picture this DTO-like class:
class LineItem : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public string Description { get; set; }
private decimal m_Amount;
public decimal Amount
{
get { return m_Amount; }
set
{
if (m_Amount == value)
return;
m_Amount = value;
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("Amount"));
}
}
}
And a binding like this:
<ItemsControl ItemsSource="{Binding LineItems}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<DockPanel>
<TextBox Text="{Binding Amount}"
DockPanel.Dock="Right" Width="50" />
<TextBlock Text="{Binding Description}" />
</DockPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
This would look something like:

Now, I want a total at the bottom. Moreover, I want it to update when Amount changes.
Something like this:
<TextBlock HorizontalAlignment="Right"
Text="{Binding LineItems,
Converter={StaticResource MyConverter}}" />
For this:

But what is MyConverter? And, is it even a correct approach?
My question:
This does not work since the converter is called only the first time it is bound. I want it to reflect user changes, and I need to handle unknown quantity of LineItems. Certainly I am not the first to hit this. Is there a way?
The results are like this:
This is the CS:
And this XAML:
What a nightmare to figure out!