I'm trying to use the SearchBox
control introduced in Windows 8.1, but I can't figure out how to display the image in the result suggestions. The suggestions appear, but the space where the image should be remains blank:
Here's my XAML:
<SearchBox SuggestionsRequested="SearchBox_SuggestionsRequested" />
And my code behind:
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();
}
}
Am I missing something?
Some extra details:
I tried to debug it with XAML Spy; each suggestion ListViewItem
has its Content
set to an instance of Windows.ApplicationModel.Search.Core.SearchSuggestion
. On these SearchSuggestion
objects, I noticed that the Text
, Tag
, DetailText
, and ImageAlternateText
properties are set to their correct value, but the Image
property is null...
EDIT: So apparently AppendResultSuggestion
accepts only an instance of RandomAccessStreamReference
, not any other implementation of IRandomAccessStreamReference
. I think this is a bug, since it's inconsistent with what is conveyed by the method signature. I filed it on Connect, please vote for it if you want it fixed!
StorageFile
an pressingF12
key, shows the declaration ofStorageFile
. ApparentlyStorageFile
already implementsIRandomAccessStreamReference
, why a different method is required? – Calvinism