2016-06-13 65 views
0

我在Mac機器上使用Xamarin Studio並在Xamarin Forms項目中工作。我的要求是 - 我有輸入字段,輸入字段的OnTextChanged事件我想只顯示ListView中那些以輸入文本開頭的項目。對於這一刻,我正在使用以下代碼來實現它 -在Xamarin Forms項目中輸入文本搜索

entry_excludeIngredients.TextChanged += (s, e) => { 

       listof_excludeIngredients.ItemsSource = container; 

       if (string.IsNullOrEmpty(entry_excludeIngredients.Text)) 
       { 
        listof_excludeIngredients.ItemsSource = null; 
        listof_excludeIngredients.IsVisible=false; 
       } 
       else 
       { 
        listof_excludeIngredients.ItemsSource = container.Where(x => x.StartsWith(entry_excludeIngredients.Text)); 
        if(listof_excludeIngredients.ItemsSource==null) 
         listof_excludeIngredients.IsVisible=false; 
        else 
         listof_excludeIngredients.IsVisible=true; 
       } 

      }; 

但是我面臨的一個問題是上面的代碼區分大小寫。如果輸入「r」,ListView只顯示以「r」開頭但不以「R」開頭的結果。

回答

0

變化

listof_excludeIngredients.ItemsSource = container.Where(x => x.StartsWith(entry_excludeIngredients.Text)); 

listof_excludeIngredients.ItemsSource = container.Where(x => x.StartsWith(entry_excludeIngredients.Text,StringComparison.CurrentCultureIgnoreCase)); 
+0

你是太美好了。 – Dipak

+0

很高興幫助:)。@ DipakAkhade –

相關問題