How to filter ListBox

余生颓废 提交于 2020-01-07 05:36:09

问题


the situation is that I have a list with some HubTile(s) in it, is there any way I can filter the ListBox depending on what is written in a TextBox?

For the text box I have the code...

private void textBoxSearch_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Enter)
        {

        }
    }

Thanks, all help appreciated!


回答1:


Sure, just store the list of HubTiles in a data structure, and when the user enters a search query, do a LINQ query on that list, and reset the list.

private List<HubTiles> myTiles;    
private void textBoxSearch_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Enter)
    {
       myList.ItemsSource = myTiles.Where(t => t.Title.Contains(textBoxSearch.Text));
    }
}


来源:https://stackoverflow.com/questions/17329122/how-to-filter-listbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!