Example #1
0
        private async void KeyWordCompleteImpl()
        {
            //if (!string.IsNullOrEmpty(KeyWord)&& (key==Key.Enter||!key.HasValue))
            //{
            //    Console.WriteLine("开始搜索......"+KeyWord);
            //}

            SearchResult.Clear();
            if (!string.IsNullOrWhiteSpace(KeyWord))
            {
                this._searchResultCancel?.Cancel();
                var newCancel = new CancellationTokenSource();
                this._searchResultCancel = newCancel;
                try
                {
                    if (SearchResultPanelVisiable == System.Windows.Visibility.Collapsed)
                    {
                        var result = await SearhResultAsync(this._searchResultCancel.Token);

                        SearchResult.AddRange(result);
                    }
                    //从其他页面导航回来时显示popup
                    else
                    {
                        await SearchAllResultAsync();
                    }
                    RaisePropertyChanged(nameof(KeyWord));
                }
                catch (OperationCanceledException)
                {
                }
                catch (AggregateException e)
                {
                    Console.WriteLine(e.InnerException);
                }
                if (this._searchResultCancel == newCancel)
                {
                    this._searchResultCancel = null;
                }
            }
        }