【问题标题】:Windows phone databinding issueWindows 手机数据绑定问题
【发布时间】:2011-10-30 20:43:26
【问题描述】:

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

class A
{
    string name;
    int totalCount;
}

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

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

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

【问题讨论】:

    标签: silverlight data-binding listbox


    【解决方案1】:
    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();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多