适合数据源为Binding的DataGrid,基本思路为:
1. 新建一个DataTable,对数据源每个row进行检索
2. 把符合条件的row信息加到新建的DataTable中
3. 将新建的DataTable作为DataGrid的数据源
private void SearchPicker_TextChanged_1(object sender, TextChangedEventArgs e)
{
String strQuery = this.SearchPicker.Text;
DataGrid dg=this.ContactList;
DataTable dtTmp = new DataTable();
for (int c = 0; c<dg.Columns.Count; c++)
{
dtTmp.Columns.Add(dg.Columns[c].Header.ToString(), typeof(String));
}
for (int i = 0; i < dtContact.Rows.Count; i++ )
{
for (int j = 0; j<dtContact.Columns.Count; j++)
{
if (dtContact.Rows[i][dg.Columns[j].Header.ToString()].ToString().ToLower().Contains(strQuery.ToLower()))
{