2011-08-19 56 views
0

我有一个自动生成的类A,如下所示。Windows手机数据绑定问题

class A 
{ 
    string name; 
    int totalCount; 
} 

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

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

在列表框模板中,我想显示两个totalCounts之间的区别,我如何使用数据绑定轻松实现这一点?

回答

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(); 
}