Windows phone databinding issue
I have an auto-generated class A which looks like the following.
class A
{
string name;
int totalCount;
}
I query the database to get list of objects, which has the most update totalCount number.
On the client side, I store the last time at which the the database was queried, so for each Object A, I have the previous totalCount.
In a listBox template, I want to show the difference between the two totalCou开发者_开发问答nts, how can I achieve this easily using databinding?
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();
}
精彩评论