public SetPropertyPrefetch ( [ options, [ |
||
options | [ | |
propertiesToRetrieve | [ |
|
return | void |
private async void Find_Click(object sender, RoutedEventArgs e) { ContentTextOutput.Text = ""; List <string> propertyNames = new List <string>(); propertyNames.Add("System.FileName"); var queryOptions = new Windows.Storage.Search.QueryOptions(); queryOptions.IndexerOption = Windows.Storage.Search.IndexerOption.OnlyUseIndexer; queryOptions.UserSearchFilter = FindQueryText.Text; queryOptions.SetPropertyPrefetch(Windows.Storage.FileProperties.PropertyPrefetchOptions.DocumentProperties, propertyNames); // Query the Pictures library. StorageFileQueryResult queryResult = Windows.Storage.KnownFolders.PicturesLibrary.CreateFileQueryWithOptions(queryOptions); IReadOnlyList <StorageFile> files = await queryResult.GetFilesAsync(); foreach (StorageFile file in files) { IDictionary <String, IReadOnlyList <Windows.Data.Text.TextSegment> > fileRangeProperties = queryResult.GetMatchingPropertiesWithRanges(file); if (fileRangeProperties.ContainsKey("System.FileName")) { IReadOnlyList <Windows.Data.Text.TextSegment> ranges; fileRangeProperties.TryGetValue("System.FileName", out ranges); rootPage.HighlightRanges(ContentTextOutput, file.DisplayName, ranges); } // Note: You can continue looking for other properties you would like to highlight on the file here. } if (files.Count == 0) { ContentTextOutput.Text = "There were no matching files in your Pictures Library"; } }
private async void Find_Click(object sender, RoutedEventArgs e) { ContentTextOutput.Text = ""; List<string> propertyNames = new List<string>(); propertyNames.Add("System.FileName"); var queryOptions = new Windows.Storage.Search.QueryOptions(); queryOptions.IndexerOption = Windows.Storage.Search.IndexerOption.OnlyUseIndexer; queryOptions.UserSearchFilter = FindQueryText.Text; queryOptions.SetPropertyPrefetch(Windows.Storage.FileProperties.PropertyPrefetchOptions.DocumentProperties, propertyNames); // Query the Pictures library. StorageFileQueryResult queryResult = Windows.Storage.KnownFolders.PicturesLibrary.CreateFileQueryWithOptions(queryOptions); IReadOnlyList<StorageFile> files = await queryResult.GetFilesAsync(); foreach (StorageFile file in files) { IDictionary<String, IReadOnlyList<Windows.Data.Text.TextSegment>> fileRangeProperties = queryResult.GetMatchingPropertiesWithRanges(file); if (fileRangeProperties.ContainsKey("System.FileName")) { IReadOnlyList<Windows.Data.Text.TextSegment> ranges; fileRangeProperties.TryGetValue("System.FileName", out ranges); rootPage.HighlightRanges(ContentTextOutput, file.DisplayName, ranges); } // Note: You can continue looking for other properties you would like to highlight on the file here. } if (files.Count == 0) { ContentTextOutput.Text = "There were no matching files in your Pictures Library"; } }
private async void GetFilesButton_Click(object sender, RoutedEventArgs e) { // Reset output. OutputPanel.Children.Clear(); // Set up file type filter. List<string> fileTypeFilter = new List<string>(); fileTypeFilter.Add(".jpg"); fileTypeFilter.Add(".png"); fileTypeFilter.Add(".bmp"); fileTypeFilter.Add(".gif"); // Create query options. var queryOptions = new QueryOptions(CommonFileQuery.OrderByName, fileTypeFilter); // Set up property prefetch - use the PropertyPrefetchOptions for top-level properties // and a list for additional properties. List<string> propertyNames = new List<string>(); propertyNames.Add(CopyrightProperty); propertyNames.Add(ColorSpaceProperty); queryOptions.SetPropertyPrefetch(PropertyPrefetchOptions.ImageProperties, propertyNames); // Set up thumbnail prefetch if needed, e.g. when creating a picture gallery view. /* const uint requestedSize = 190; const ThumbnailMode thumbnailMode = ThumbnailMode.PicturesView; const ThumbnailOptions thumbnailOptions = ThumbnailOptions.UseCurrentScale; queryOptions.SetThumbnailPrefetch(thumbnailMode, requestedSize, thumbnailOptions); */ // Set up the query and retrieve files. StorageFolder picturesFolder = await KnownFolders.GetFolderForUserAsync(null /* current user */, KnownFolderId.PicturesLibrary); var query = picturesFolder.CreateFileQueryWithOptions(queryOptions); IReadOnlyList<StorageFile> fileList = await query.GetFilesAsync(); foreach (StorageFile file in fileList) { OutputPanel.Children.Add(CreateHeaderTextBlock(file.Name)); // GetImagePropertiesAsync will return synchronously when prefetching has been able to // retrieve the properties in advance. var properties = await file.Properties.GetImagePropertiesAsync(); OutputPanel.Children.Add(CreateLineItemTextBlock("Dimensions: " + properties.Width + "x" + properties.Height)); // Similarly, extra properties are retrieved asynchronously but may // return immediately when prefetching has fulfilled its task. IDictionary<string, object> extraProperties = await file.Properties.RetrievePropertiesAsync(propertyNames); var propValue = extraProperties[CopyrightProperty]; OutputPanel.Children.Add(CreateLineItemTextBlock("Copyright: " + GetPropertyDisplayValue(propValue))); propValue = extraProperties[ColorSpaceProperty]; OutputPanel.Children.Add(CreateLineItemTextBlock("Color space: " + GetPropertyDisplayValue(propValue))); // Thumbnails can also be retrieved and used. // var thumbnail = await file.GetThumbnailAsync(thumbnailMode, requestedSize, thumbnailOptions); } }