Guest User

my VM

a guest
May 12th, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1.     using PropertyChanged;
  2.  
  3.     [ImplementPropertyChanged]
  4.     public class SearchViewModel : ViewModelBase
  5.     {
  6. ...
  7.  
  8.             IObservable<IEnumerable<SearchDisplay>> searchedStrings = SearchText.
  9.                 Where(x => !string.IsNullOrEmpty(x)).
  10.                 Throttle(TimeSpan.FromSeconds(1)).
  11.                 DistinctUntilChanged().
  12.                 Select(SearchForText).
  13.                 Switch();
  14.             searchedStrings.Subscribe(matches =>
  15.                 {
  16.                     ItemsSource.ClearOnScheduler();
  17.                     ItemsSource.AddRangeOnScheduler(matches);
  18.                     Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
  19.                         {
  20.                             if (ItemsSource.Count == 0)
  21.                                 ItemsSource.AddOnScheduler(new SearchDisplay(0L, SearchDisplayType.NotFound));
  22.                         }
  23.                     ));
  24.                 });
  25. ...
  26.         public ReactiveProperty<string> SearchText { get; set; }
  27.         public ReactiveCollection<SearchDisplay> ItemsSource { get; private set; }
  28. ...
  29.  
  30.         private async Task<IEnumerable<SearchDisplay>> SearchForText(string searchedText)
  31.         {
  32.             return await Task.FromResult(...);
  33.         }
  34.  
  35.  
  36. ...
Advertisement
Add Comment
Please, Sign In to add comment