Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用反应式扩展来限制SearchPane.SuggestionRequested?_C#_Windows 8_Windows Store Apps_Winrt Xaml_System.reactive - Fatal编程技术网

C# 如何使用反应式扩展来限制SearchPane.SuggestionRequested?

C# 如何使用反应式扩展来限制SearchPane.SuggestionRequested?,c#,windows-8,windows-store-apps,winrt-xaml,system.reactive,C#,Windows 8,Windows Store Apps,Winrt Xaml,System.reactive,被动扩展允许我“观察”一系列事件。例如,当用户在Windows 8搜索窗格中键入他们的搜索查询时,SuggestionRequested会一次又一次地(针对每个字母)提出。如何利用反应式扩展来限制请求 大概是这样的: SearchPane.GetForCurrentView().SuggestionsRequested += (s, e) => { if (e.QueryText.Length < 3) return; // TODO: if iden

被动扩展允许我“观察”一系列事件。例如,当用户在Windows 8搜索窗格中键入他们的搜索查询时,SuggestionRequested会一次又一次地(针对每个字母)提出。如何利用反应式扩展来限制请求

大概是这样的:

SearchPane.GetForCurrentView().SuggestionsRequested += (s, e) =>
{
    if (e.QueryText.Length < 3)
        return;
    // TODO: if identical to the last request, return;
    // TODO: if asked less than 500ms ago, return;
};
SearchPane.GetForCurrentView().SuggestionRequested+=(s,e)=>
{
如果(e.QueryText.Length<3)
返回;
//TODO:如果与上一个请求相同,则返回;
//TODO:如果在500毫秒前询问,返回;
};
解决方案

System.Reactive.Linq.Observable.FromEventPattern<Windows.ApplicationModel.Search.SearchPaneSuggestionsRequestedEventArgs>
    (Windows.ApplicationModel.Search.SearchPane.GetForCurrentView(), "SuggestionsRequested")
    .Throttle(TimeSpan.FromMilliseconds(500), System.Reactive.Concurrency.Scheduler.CurrentThread)
    .Where(x => x.EventArgs.QueryText.Length > 3)
    .DistinctUntilChanged(x => x.EventArgs.QueryText.Trim())
    .Subscribe(x => HandleSuggestions(x.EventArgs));
System.Reactive.Linq.Observable.FromEventPattern
(Windows.ApplicationModel.Search.SearchPane.GetForCurrentView(),“SuggestionsRequested”)
.Throttle(TimeSpan.From毫秒(500),System.Responsive.Concurrency.Scheduler.CurrentThread)
.Where(x=>x.EventArgs.QueryText.Length>3)
.DistinctUntilChanged(x=>x.EventArgs.QueryText.Trim())
.Subscribe(x=>HandleSuggestions(x.EventArgs));
为WinRT安装RX: 了解更多信息:

有多种方法


你想怎么做就怎么做。

@JerryNixon MSFT哦,很抱歉:)它在我浏览时弹出。。。很高兴我是对的。
System.Reactive.Linq.Observable.FromEventPattern<Windows.ApplicationModel.Search.SearchPaneSuggestionsRequestedEventArgs>
    (Windows.ApplicationModel.Search.SearchPane.GetForCurrentView(), "SuggestionsRequested")
    .Throttle(TimeSpan.FromMilliseconds(500), System.Reactive.Concurrency.Scheduler.CurrentThread)
    .Where(x => x.EventArgs.QueryText.Length > 3)
    .DistinctUntilChanged(x => x.EventArgs.QueryText.Trim())
    .Subscribe(x => HandleSuggestions(x.EventArgs));
.DistinctUntilChanged(e => e.QueryText.Trim())