I'm making a small personal finance program that uses "envelopes" as the budgeting method. I'm mostly doing this as a means to learn WPF & MVVM. I've run into a problem where I can't databind to the custom properties I created in my custom ObservableCollection, seen here:
public class ObservableEnvelopeCollection : ObservableCollection<Envelope>
{
public decimal Total
{
get
{
decimal total = 0;
foreach (Envelope env in this)
{
total += env.Balance;
}
return total;
}
}
public decimal SavingsTotal
{
get
{
blah blah. . .
}
}
}
I'm able to databind my datagrid to the collection with no trouble, however below my datagrid I have labels that I need to display the total of balances for the envelopes in the collection. I'm able to databind to the Count property of the collection, which is a property of the parent ObservableCollection class, but I can't databind to Total or SavingsTotal from my custom class.
The label is just blank when the program is run, and if I use the VS2010 designer and go to the little databinding wizard for the label's Content, it has 'Total' underlined and shows the tooltip: "Path item 'Total' could not be resolved." Again, if I change Path to EnvColl.Count it works.
<Label Content="{Binding Path=EnvColl.Total}"/>
One more note, in my ViewModel I can access the Total and SavingsTotal properties in my collection with no problem, it's just in XAML/databinding that it doesn't work.