【问题标题】:How do I sort a list with more than 1 item? I can only get it to sort the list with 1 item如何对超过 1 个项目的列表进行排序?我只能用 1 项对列表进行排序
【发布时间】:2015-12-25 16:20:24
【问题描述】:

代码看起来像这样,正如我在标题中提到的那样,代码有效,但仅适用于 1 项,但我希望它使用附加项目搜索列表。

这是我的功能代码(1 项名为 irl1):

private void FilterContacts(string filter)
{
    EmployeeList.BeginRefresh();

    if (string.IsNullOrWhiteSpace(filter)) {
        System.Diagnostics.Debug.WriteLine("if1");
        EmployeeList.ItemsSource = ourPitems;
    } else {
        System.Diagnostics.Debug.WriteLine("else2");
        EmployeeList.ItemsSource = ourPitems.Where(x => x.irl1.ToLower ().Contains (filter.ToLower ()));
    }

    EmployeeList.EndRefresh ();
}

而我正在尝试做的事情不起作用:

EmployeeList.ItemsSource = 
    ourPitems.Where(
        x => x.ourMadeUpNationality.ToLower(), 
        oem => oem.irl1.ToLower().Contains(filter.ToLower())
    );

当我在它的时候,我试图让列表在我向上拖动时刷新,但它只是继续加载,当我在我的列表中搜索时它会更新。我试图做的是这个,但它似乎不起作用。

public StartPage()
{
    InitializeComponent();

    //add the refresh function here.

    EmployeeList.BeginRefresh();
    // this is for the search list.
    sbSearch.TextChanged += (sender2, e2) => FilterContacts(sbSearch.Text);
    // this is for the search list.
    sbSearch.SearchButtonPressed += (sender2, e2) => FilterContacts(sbSearch.Text);

    EmployeeList.EndRefresh();
}

【问题讨论】:

  • 幽默风趣!用一个项目对列表进行排序(甚至成功!)。
  • 你好像问了两个问题。最好单独提出问题。一个人可能只知道你的一个问题的答案,但他不能回答,因为他没有完全回答你的问题,而且其他人可能会否决他。
  • 是的,我可能在那里超前了 :P 但问题有点相同,所以我想到底是怎么回事。希望有人可以帮助我。
  • 列表现在用我拥有的一个项目完美地排序,我只想让它按 2 个不同的项目排序!
  • 顺便说一句,您可以使用 && 之类的运算符。 x => x.ourMadeUpNationality.ToLower().Contains(...) && x.irl1.ToLower().Contains(....)(那个人就是我;))

标签: c# forms xamarin


【解决方案1】:

EmployeeList.ItemsSource = ourPitems.Where(tk => tk.irl1.ToLower().Contains(filter.ToLower()) && tk.ourMadeUpNationality == "Test1");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-03
    • 1970-01-01
    相关资源
    最近更新 更多