2014-02-27 113 views
1

我正在爲Windows Phone 7構建一個應用程序,我需要搜索框。在點擊搜索框時,它應該顯示web服務中已存在的城市名稱。我不知道如何繼續。請幫助我的Windows Phone 7應用程序中的搜索框

+0

@ har07嘿,你能給我一些這個想法 – bhaku

+0

你的意思是AutoCompleteBox? –

+0

@ChrisShao Ya autocompletebox。我已經做到了。請參閱我在新問題中發佈的代碼 – bhaku

回答

1

我想你需要的是AutoCompleteBox在WP工具,使用它像這樣: 只是數據源綁定到AutoCompleteBox並設置ItemFilter

XAML:

<toolkit:AutoCompleteBox x:Name="peopleBox" Height="70"/> 

代碼:

this.peopleBox.ItemsSource = myDataSource; 
this.peopleBox.ItemFilter += SearchCountry; 

SearchCountry是:

bool SearchCountry(string search, object value) 
     { 
      if (value != null) 
      { 
       //return true if it contains the search key 
       if (value.ToString().ToLower().IndexOf(search) >= 0) 
        return true; 
      } 
      // if not, return false 
      return false; 
     } 
+0

它不起作用 – bhaku

+0

有什麼事嗎? –

+0

像普通文本框 – bhaku