Image not shown for search suggestions in SearchBox

I am trying to use the SearchBox control introduced in Windows 8.1, but I cannot figure out how to display the image in the result sentences. Suggestions will appear, but the space in which the image should be remains empty:

enter image description here

Here is my xaml:

 <SearchBox SuggestionsRequested="SearchBox_SuggestionsRequested" /> 

And my code is:

  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(); } } 

Did I miss something?


Additional information:

I tried debugging it using XAML Spy; each ListViewItem clause has its own Content for the Windows.ApplicationModel.Search.Core.SearchSuggestion instance. On these SearchSuggestion objects SearchSuggestion I noticed that the Text , Tag , DetailText and ImageAlternateText set to their correct value, but the Image property is null ...


EDIT: Thus, it is obvious that AppendResultSuggestion accepts only an instance of RandomAccessStreamReference , and not any other implementation of IRandomAccessStreamReference . I think this is a mistake because it is incompatible with the fact that the method signature is passed. I submitted it to Connect , vote for it if you want it to be fixed!

+6
source share
1 answer

Signature AppendResultSuggestion calls IRandomAccessStreamReference :

 public void AppendResultSuggestion( string text, string detailText, string tag, IRandomAccessStreamReference image, string imageAlternateText) 

You can get it if you already have a StorageFile (which you are doing) using CreateFromFile :

 RandomAccessStreamReference.CreateFromFile(IStorageFile file) 

But since you are starting with a URI, you can also skip the extra step and use CreateFromUri :

 RandomAccessStreamReference.CreateFromUri(Uri uri) 

So you will have something like:

 var imageUri = new Uri("ms-appx:///test.png"); var imageRef = RandomAccessStreamReference.CreateFromUri(imageUri); args.Request.SearchSuggestionCollection.AppendResultSuggestion("foo", "Details", "foo", imageRef, "Result") 
+5
source

Source: https://habr.com/ru/post/957344/


All Articles