我有一个包含搜索框的用户控件。这个 UserControl 在另一个里面。
我在搜索时遇到了一个奇怪的行为,因为SuggestionCollection 以一种奇怪的方式工作。
例子 :
在搜索框中,我写的东西都可以正常工作,如果我选择它也可以工作。但是,如果我尝试使用退格键(在选择之后),我没有得到任何建议。我不明白为什么它不起作用。
那是代码
//var deferral = args.Request.GetDeferral(); //it seems to not influence the behavior
var suggestionCollection = args.Request.SearchSuggestionCollection;
try
{
TransporterExt tr_search = new TransporterExt();
//queryText is a string inserted in the searchBox
if (string.IsNullOrEmpty(queryText)) return;
tr_search.name = queryText;
suggested.Clear(); //that's a collection..
//just a search that return a collection of objects TransporterExt
querySuggestions = await TransporterService.Search_StartsWith(tr_search);
if (querySuggestions.Count > 0)
{
int i = 0;
foreach (TransporterExt tr in querySuggestions)
{
string name = tr.name;
string detail = tr.trId.ToString();
string tag = i.ToString();
string imageAlternate = "imgDesc";
suggestionCollection.AppendResultSuggestion(name, detail, tag, imgRef, imageAlternate);
this.suggested.Add(tr);
i++;
}
}
}
catch (System.ArgumentException exc)
{
//Ignore any exceptions that occur trying to find search suggestions.
Debug.WriteLine(exc.Message);
Debug.WriteLine(exc.StackTrace);
}
//deferralComplete(); //it seems to not influence the behavior
问题是:所有变量都有正确的值,但建议面板仅在我进行特定搜索时出现:当我更改搜索的第一个字母或错误搜索后出现
当我进行搜索时会附加什么
如果我使用退格键会附加什么,我想修复什么
正如我所说,一切正常,在“退格”操作后suggestionCollection
得到了正确的值......但面板丢失了。有人可以帮助我吗?