2016-10-28 11 views
-2
<Grid Grid.Row="3"> 
    <SearchBox ChooseSuggestionOnEnter="True" FontSize="44 
       SearchHistoryEnabled="True" PlaceholderText="Select City" 
       SuggestionsRequested="SearchBox_SuggestionsRequested" /> 
</Grid> 

クエリを更新して検索結果をコレクションに更新する方法を教えてください。私はUWPアプリをやっていますが、私は検索ボックスを見つけましたが、Autosuggestboxは検索結果を送るためにクエリを送信してコンボボックスをバインドしませんでしたか?

答えて

0

クエリを更新して検索結果をコレクションに戻すにはどうすればよいですか?

SearchBox.QuerySubmittedイベントを使用すると、クエリ操作を処理できます。このイベント内の検索結果であなたのコレクションを更新してください。以下のような

シンプルなコードは次のとおりサーチについて

private void mySearchBox_QuerySubmitted(SearchBox sender, SearchBoxQuerySubmittedEventArgs args) 
{ 
    ObservableCollection<string> newcollection = new ObservableCollection<string> { }; 
    string querystring = args.QueryText; 
    foreach(string item in collection) 
    { 
     if(item.Contains(querystring)) 
     { 
      newcollection.Add(item); 
     } 
    } 
    comsearch.ItemsSource = newcollection; 
} 

詳細をthis official sampleを参照してください。しかし、SearchBoxクラスの説明によると、Universal Windows Platform(UWP)アプリケーションにはお勧めできません。

SearchBoxはユニバーサルデバイスファミリに実装されていますが、モバイルデバイスでは完全に機能していません。あなたの普遍的な検索の経験のためにAutoSuggestBoxを使用してください。 SearchBox deprecated in favor of AutoSuggestBoxを参照してください。

関連する問題