locked
FileInformationFactory.GetVirtualizedFilesVector() used as source in FlipView Problem (Get Data From PicturesLibrary)

    Question

  • Hi all,

    I have looked the sample:StorageDataSource and GetVirtualizedFilesVector sample and I want to use FileInformationFactory.GetVirtualizedFilesVector() to implement a gallery in FlipView.

    In my Scenario , I want to get pictures from a folder in PicturesLibrary, and Display them in Flipview, when I tried to use  FileInformationFactory.GetVirtualizedFilesVector() to set as source of Flipview, I have met some problems.

    First, in the sample above, they use thumbnail properties to show pictures in PicturesLibrary, however I want to show the original image instead of thumbnail,so I have created an converter and get Fileinformation as source, trying to get the Image Source from the Fileinformation data.

    Because I want to get the picture from Picturelibrary, I can't use BitmapImage(new Uri(Path)) to get the ImageSource, on the other hand I have tried use FileInformation.OpenAsync() to get the stream and set as BitmapImageSource , but it couldn't work either,Since the Convert() function could not be an async function.

    Is there any good idea for my scenario?

    Thanks,

    Bob



     


     


    • Edited by Bob_Yeh Sunday, May 6, 2012 7:47 AM
    Sunday, May 6, 2012 7:45 AM

All replies

  • Do you mind posting your code for me?  I'll play with it to see what we can do.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator If my reply answers your question, please mark this post as answered.

    Monday, May 7, 2012 6:58 PM
    Moderator
  • Hi Matt,

    Thanks for your reply,

    So far, I have got the code below

    In my xaml:

    <Grid Background="{StaticResource ApplicationPageBackgroundBrush}">
            <Grid.Resources>
                <local:ImageConverter x:Key="myImageConverter" />
            </Grid.Resources>
            <FlipView x:Name="FVGallery">
                <FlipView.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Image Source="{Binding Converter={StaticResource myImageConverter} }"/>
                        </Grid>
                    </DataTemplate>
                </FlipView.ItemTemplate>
                <FlipView.ItemsPanel>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel Orientation="Horizontal"  />
                    </ItemsPanelTemplate>
                </FlipView.ItemsPanel>
            </FlipView>
        </Grid>

    myImageCoverter:

    public class ConverterBase : IValueConverter
        {
            public virtual object Convert(object value, Type targetType, object parameter, string culture) { return null; }
            public virtual object ConvertBack(object value, Type targetType, object parameter, string culture) { return null; }
        }
    
        public class ImageConverter : ConverterBase
        {
            BitmapImage bi;
    
            public override object Convert(object value, Type targetType, object parameter, string culture)
            {
                if (value != null)
                {
                    FileInformation pictureFile = value as FileInformation;
                    GetImageSource(pictureFile);
                    /****Can Convert Function be an async function return ImageSource?
                    IRandomAccessStream stream =await pictureFile.OpenAsync(Windows.Storage.FileAccessMode.Read);
                    BitmapImage bi = new BitmapImage();
                    bi.SetSource(stream);
                    */            
                    return bi;
                }
                return DependencyProperty.UnsetValue;
            }
    
            public async void GetImageSource(FileInformation pictureFile)
            {
                bi = new BitmapImage();
                IRandomAccessStream stream =await pictureFile.OpenAsync(Windows.Storage.FileAccessMode.Read);
                bi.SetSource(stream);
            }
        }


    In my code behind:

    public void PhotoEnumerate()
            {
                var library = Windows.Storage.KnownFolders.PicturesLibrary;
                var queryOptions = new Windows.Storage.Search.QueryOptions();
                queryOptions.FolderDepth = Windows.Storage.Search.FolderDepth.Deep;
                queryOptions.IndexerOption = Windows.Storage.Search.IndexerOption.UseIndexerWhenAvailable;
    
                var fileQuery = library.CreateFileQueryWithOptions(queryOptions);
    
                var fif = new Windows.Storage.BulkAccess.FileInformationFactory(
                    fileQuery,
                    Windows.Storage.FileProperties.ThumbnailMode.PicturesView,
                    190,
                    Windows.Storage.FileProperties.ThumbnailOptions.UseCurrentScale,
                    false
                    );
    
                var dataSource = fif.GetVirtualizedFilesVector();
                FVGallery.ItemsSource = dataSource;
            }

    By the code above, I have met the bugs below,

    First, when I swipe the Flipview to  the next page, it sometimes jump back to the previous pages(about 5 to 8 pages)

    Second,The code sometimes blocked when excuting "FVGallery.ItemsSource = dataSource;"  with the Exception:Value does not fall within the expected range.

    Third,the FlipView shut down and couldn't swipe very often.

    Hope you guys could help me solve the problem,

    thanks,

    Bob 

     

     

     

    Tuesday, May 8, 2012 5:04 AM
  • Where does the method PhotoEnumerate go?  How does it get called?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    Monday, May 14, 2012 1:53 PM
    Moderator
  • Hi Matt,

    Thanks for your reply,

    The PhotoEnumerate was called when  the user click a button,then the page will navigate to the gallery page where my FVGallery is. 

    Thanks,

       Bob



    • Edited by Bob_Yeh Friday, May 18, 2012 1:47 AM
    Friday, May 18, 2012 1:47 AM
  • Bob, can you just send me a working project?  MSMALL at Microsoft.  Thank you.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    Friday, May 18, 2012 2:03 PM
    Moderator