【发布时间】:2013-11-04 14:19:01
【问题描述】:
我正在尝试使用 Windows 8.1 中引入的 SearchBox 控件,但我不知道如何在结果建议中显示图像。建议出现了,但图像应该是空白的空间:
这是我的 XAML:
<SearchBox SuggestionsRequested="SearchBox_SuggestionsRequested" />
还有我的代码:
private async void SearchBox_SuggestionsRequested(SearchBox sender, SearchBoxSuggestionsRequestedEventArgs args)
{
var deferral = args.Request.GetDeferral();
try
{
var imageUri = new Uri("ms-appx:///test.png");
var imageRef = await StorageFile.GetFileFromApplicationUriAsync(imageUri);
args.Request.SearchSuggestionCollection.AppendQuerySuggestion("test");
args.Request.SearchSuggestionCollection.AppendSearchSeparator("Foo Bar");
args.Request.SearchSuggestionCollection.AppendResultSuggestion("foo", "Details", "foo", imageRef, "Result");
args.Request.SearchSuggestionCollection.AppendResultSuggestion("bar", "Details", "bar", imageRef, "Result");
args.Request.SearchSuggestionCollection.AppendResultSuggestion("baz", "Details", "baz", imageRef, "Result");
}
finally
{
deferral.Complete();
}
}
我错过了什么吗?
一些额外的细节:
我尝试使用 XAML Spy 对其进行调试;每个建议ListViewItem 都将其Content 设置为Windows.ApplicationModel.Search.Core.SearchSuggestion 的一个实例。在这些SearchSuggestion 对象上,我注意到Text、Tag、DetailText 和ImageAlternateText 属性设置为正确的值,但Image 属性为空...
编辑:显然AppendResultSuggestion 只接受RandomAccessStreamReference 的一个实例,而不接受IRandomAccessStreamReference 的任何其他实现。我认为这是一个错误,因为它与方法签名所传达的内容不一致。我filed it on Connect,如果你想修复它,请投票给它!
【问题讨论】:
标签: c# xaml windows-runtime windows-8.1 search-box