0
我有一個使用RadGridView控件的Silverlight應用程序。當用戶更新列中的值時,我希望總和得到更新。此行爲顯示在Telerik演示站點上。我有一種預感,那就是我的觀點模型。但是,我不確定。這是我的觀點和視圖模型的片段。通過XAML中的數組索引進行雙向綁定
查看
<telerik:RadGridView>
<telerik:GridViewDataColumn Header="Column1" DataMemberBinding="{Binding Path=Tally[0], Mode=TwoWay}">
<telerik:GridViewDataColumn.AggregateFunctions>
<telerik:SumFunction ResultFormatString="{}{0:N2}" SourceField="Tally[0]" />
</telerik:GridViewDataColumn.AggregateFunctions>
</telerik:GridViewDataColumn>
<telerik:GridViewDataColumn Header="Column2" DataMemberBinding="{Binding Path=Tally[1], Mode=TwoWay}">
<telerik:GridViewDataColumn.AggregateFunctions>
<telerik:SumFunction ResultFormatString="{}{0:N2}" SourceField="Tally[1]" />
</telerik:GridViewDataColumn.AggregateFunctions>
</telerik:GridViewDataColumn>
<telerik:GridViewDataColumn Header="Column3" DataMemberBinding="{Binding Path=Tally[2], Mode=TwoWay}">
<telerik:GridViewDataColumn.AggregateFunctions>
<telerik:SumFunction ResultFormatString="{}{0:N2}" SourceField="Tally[2]" />
</telerik:GridViewDataColumn.AggregateFunctions>
</telerik:GridViewDataColumn>
</telerik:RadGridView>
視圖模型
public class MyViewModel : ViewModel
{
private ObservableCollection<Item> items = Item.GetAll();
public ObservableCollection<Item> Items
{
get { return items; }
set {
items = value;
NotifyPropertyChanged("Items");
}
}
}
public class Item : ViewModel
{
private List<int> tally = new List<int>();
public List<int> Tally
{
get { return tally; }
set
{
tally = value;
NotifyPropertyChanged("Tally");
}
}
public Item()
{
for (int i = 0; i < 10; i++)
this.Tally.Add(i);
}
public static ObservableCollection<Item> GetAll()
{
ObservableCollection<Item> items = new ObservableCollection<Item>();
for (int i = 0; i < 10; i++)
items.Add(new Item(i));
return items;
}
}
爲什麼總和沒有更新?