Windows手机数据绑定问题

时间:2011-08-19 18:51:46

标签: silverlight data-binding listbox

我有一个自动生成的A类,如下所示。

class A
{
    string name;
    int totalCount;
}

我查询数据库以获取具有最多更新totalCount编号的对象列表。

在客户端,我存储查询数据库的最后一次,因此对于每个对象A,我有以前的totalCount。

在listBox模板中,我想显示两个totalCounts之间的差异,如何使用数据绑定轻松实现这一点?

1 个答案:

答案 0 :(得分:0)

class A
{
    string name;
    int totalCount;
}
class Differences
{
    string name;
    int oldCount;
    int newCount;
    int differenceInCount;
}
//this has been set somewhere
private List<A> previousValues;
//assume this is going to be set with the next call.
private List<A> updatedValues;

//A listbox can be bound to the result of this function.
private List<Differences> CalculateDifference(){
    List<Differences> retval = new List<Differences>;
    Differences temp;
    foreach(A updated in updatedValues)
    {
        foreach(A previous in previousValues){
            if(updated.name == previous.name){
                temp = new Differences;
                temp.name = updated.name;
                temp.oldCount = previous.totalCount;
                temp.newCount = updated.totalCount;
                temp.differenceInCount = temp.newCount - temp.oldCount;
                retval.Add(temp);
                break;
            }
        }
    }
    return retval();
}