Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using PropertyChanged;
- [ImplementPropertyChanged]
- public class SearchViewModel : ViewModelBase
- {
- ...
- IObservable<IEnumerable<SearchDisplay>> searchedStrings = SearchText.
- Where(x => !string.IsNullOrEmpty(x)).
- Throttle(TimeSpan.FromSeconds(1)).
- DistinctUntilChanged().
- Select(SearchForText).
- Switch();
- searchedStrings.Subscribe(matches =>
- {
- ItemsSource.ClearOnScheduler();
- ItemsSource.AddRangeOnScheduler(matches);
- Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
- {
- if (ItemsSource.Count == 0)
- ItemsSource.AddOnScheduler(new SearchDisplay(0L, SearchDisplayType.NotFound));
- }
- ));
- });
- ...
- public ReactiveProperty<string> SearchText { get; set; }
- public ReactiveCollection<SearchDisplay> ItemsSource { get; private set; }
- ...
- private async Task<IEnumerable<SearchDisplay>> SearchForText(string searchedText)
- {
- return await Task.FromResult(...);
- }
- ...
Advertisement
Add Comment
Please, Sign In to add comment