本文整理汇总了C#中ReactiveProperty.Throttle方法的典型用法代码示例。如果您正苦于以下问题:C# ReactiveProperty.Throttle方法的具体用法?C# ReactiveProperty.Throttle怎么用?C# ReactiveProperty.Throttle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReactiveProperty
的用法示例。
在下文中一共展示了ReactiveProperty.Throttle方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MainViewModel
public MainViewModel()
{
_directoryToMonitor = new DirectoryInfo(Properties.Settings.Default.DirectoryToObserve);
_fileEndingFilters = Properties.Settings.Default.FileFilters.Split(' ');
SearchTerm = new ReactiveProperty<string>();
_episodes = new ObservableCollection<Episode>();
_allEpisodes = new List<Episode>();
var loadedEpisodes = from _ in Observable.Interval(TimeSpan.FromSeconds(5)).Merge(Observable.Return(0L))
let files = GetFiles(_directoryToMonitor.ToString(), _fileEndingFilters, SearchOption.AllDirectories)
select files.Select(file => new Episode(new FileInfo(file))).ToList();
loadedEpisodes.Subscribe(files =>
{
_allEpisodes = files;
});
var searchClickEvents = SearchTerm.Throttle(TimeSpan.FromMilliseconds(100));
searchClickEvents.ObserveOn(SynchronizationContext.Current).Subscribe(_ =>
{
var episodes = from episode in _allEpisodes
where IsContainedInFilter(episode.File.Name)
select episode;
_episodes.Clear();
foreach (var episode in episodes)
_episodes.Add(episode);
});
}
示例2: MainWindowVm
public MainWindowVm()
{
SelectedRepository
.AddTo(MultipleDisposable);
Repositories = App.Instance.Repositories
.ToReadOnlyReactiveCollection(x => new RepositoryVm(x, this))
.AddTo(MultipleDisposable);
Title = SelectedRepository
.Select(x => x == null ? "Anne" : "Anne -- " + x.Path)
.ToReadOnlyReactiveProperty()
.AddTo(MultipleDisposable);
Filter = new ReactiveProperty<string>(string.Empty)
.AddTo(MultipleDisposable);
Filter
.Throttle(TimeSpan.FromMilliseconds(300))
.Where(_ => SelectedRepository.Value != null)
.Subscribe(x => SelectedRepository.Value.WordFilter.Value = new WordFilter(x))
.AddTo(MultipleDisposable);
SelectedRepository
.Subscribe(_ => Filter.Value = string.Empty)
.AddTo(MultipleDisposable);
SelectedRepository.Value = Repositories.FirstOrDefault();
Repositories
.CollectionChangedAsObservable()
.Where(_ => SelectedRepository.Value == null)
.Subscribe(_ => SelectedRepository.Value = Repositories.FirstOrDefault())
.AddTo(MultipleDisposable);
// 現在のフォーカスを持っているコントロールを表示する
#if false
Task.Run(() =>
{
while (true)
{
Application.Current.Dispatcher.Invoke(() => Debug.WriteLine(Keyboard.FocusedElement));
Thread.Sleep(1000);
}
});
#endif
}