Beispiel #1
0
 private void SearchBar_TextChanged(object sender, TextChangedEventArgs e)
 {
     if (SearchBar.Text?.Length > 2)
     {
         //viewModel.LoadSearchResultsCommand.Execute(SearchBar.Text);
         Interlocked.Exchange(ref this.throttleCts, new CancellationTokenSource()).Cancel();
         Task.Delay(TimeSpan.FromMilliseconds(500), this.throttleCts.Token)                 // if no keystroke occurs, carry on after 500ms
         .ContinueWith(
             delegate { viewModel.LoadSearchResultsCommand.Execute(SearchBar.Text); },
             CancellationToken.None,
             TaskContinuationOptions.OnlyOnRanToCompletion,
             TaskScheduler.FromCurrentSynchronizationContext());
     }
     else
     {
         viewModel.ClearResults();
     }
 }