2011-08-19 33 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(); 
}