如何过滤ListBox [英] How to filter ListBox

查看:144
本文介绍了如何过滤ListBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况是我有一个HubTile在其中的列表,有没有什么办法可以过滤ListBox取决于在TextBox中写什么?





  private void textBoxSearch_KeyDown(object sender,KeyEventArgs e)

如果(e.Key == Key.Enter)
{



code $ pre>

谢谢,所有帮助表示感谢!

解决方案

将HubTile列表存储在数据结构中,当用户输入搜索查询时,对该列表执行LINQ查询,并重置该列表。

 私人列表< 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));
}
}


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!

解决方案

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));
    }
}

这篇关于如何过滤ListBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆