为Windows应用商店8.1构建应用,我按照教程实现了我的搜索框。 但是,只搜索" startWith"另一个。
如果我尝试使用" contains"我迷恋了,一个未经处理的例外。
它在第一个工作,但如果我在搜索框中更改查询它会粉碎...经常,而不是总是。
我无法理解调试器消息,因为它引用了应用程序代码......
这是我的调试器消息
Debugger:Debugger Break
A break in the debugger session because a user paused the session.
Time: 13/04/2014 12:34:34
Thread:<No Name>[6220]
并参考
#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException += (sender, e) =>
{
if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
};
#endif
}
我的e对象出现异常:参数不正确,处理:false ....
那是我的SuggestionRequested函数,哪里有问题(我认为)
public async void OnSuggest(SearchBox sender, SearchBoxSuggestionsRequestedEventArgs args)
{
var deferral = args.Request.GetDeferral();
TransporterExt tr_search = new TransporterExt();
ObservableCollection<TransporterExt> querySuggestions = new ObservableCollection<TransporterExt>();
var queryText = args.QueryText != null ? args.QueryText.Trim() : null;
if (string.IsNullOrEmpty(queryText)) return;
suggested.Clear();
tr_search.name = queryText;
try
{
var suggestionCollection = args.Request.SearchSuggestionCollection;
querySuggestions = await TransporterService.Search(tr_search);
if (querySuggestions != null && querySuggestions.Count > 0 )
{
int i = 0;
foreach (TransporterExt tr in querySuggestions)
{
string strB = sender.QueryText;
string strA = tr.name;
if(await Utility.Compare(strA,strB))
//using this condition all works fine
//if (tr.name.StartsWith(sender.QueryText, StringComparison.CurrentCultureIgnoreCase))
{
string name = tr.name;
string detail = tr.trId.ToString();
string tag = i.ToString();
string imageAlternate = "imgDesc";
suggestionCollection.AppendResultSuggestion(name, detail, tag, imgRef, imageAlternate);
if(tr!=null)
suggested.Add(tr);
i++;
}
}
}
}
catch (Exception exc)
{
//Ignore any exceptions that occur trying to find search suggestions.
Debug.WriteLine("Exception " + exc.Message);
Debug.WriteLine(exc.StackTrace);
}
deferral.Complete();
}
和包含实用程序
public static async Task<bool>Compare(string A, string B) {
bool contains = Regex.Match(A, B, RegexOptions.IgnoreCase).Success;
Debug.WriteLine("regex ="+contains);
return contains;
}
我在UserControl中获得了这个SearchBox,这是我的UC的代码
public delegate void SuggestionsRequested(SearchBox sender, SearchBoxSuggestionsRequestedEventArgs args);
public event Windows.Foundation.TypedEventHandler<SearchBox, SearchBoxSuggestionsRequestedEventArgs> SearchBoxSuggestionsRequested;
private void SearchBoxSuggestions(SearchBox sender, SearchBoxSuggestionsRequestedEventArgs args)
{
if (SearchBoxSuggestionsRequested != null)
SearchBoxSuggestionsRequested(sender, args);
else
Debug.WriteLine("TruckFormUCException");
}
可以使用其他逻辑进行搜索,而不是&#34;从#34开始??...我的错?