0
votes

I need to show all photo present in a my device (WP8) in a LongListMultiSelector. i use this method

 MediaPlayer.Queue.ToString();
        MediaLibrary mediaLibrary;
        PictureAlbum cameraRoll = null;


        foreach (MediaSource source in MediaSource.GetAvailableMediaSources())
        {
            if (source.MediaSourceType == MediaSourceType.LocalDevice)
            {
                mediaLibrary = new MediaLibrary(source);
                PictureAlbumCollection allAlbums = mediaLibrary.RootPictureAlbum.Albums;
                foreach (PictureAlbum album in allAlbums)
                {
                    if (album.Name == "Camera Roll")
                    {
                        cameraRoll = album;
                    }
                }
            }
        }

        List<BitmapImage> lstBitmapImage = new List<BitmapImage>();
        foreach (Picture p in cameraRoll.Pictures)
        {
            BitmapImage b = new BitmapImage();
            b.SetSource(p.GetThumbnail());
            lstBitmapImage.Add(b);
        }


        PhotoHubLLS.ItemsSource = lstBitmapImage;

In a XAML i have this image setting

<Image HorizontalAlignment="Left" Margin="6,6,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Source="{Binding}"/>

It all works perfectly, but I have some questions.

I would like to Zoom on single picture, on image tap i'm insert this code

FrameworkElement fe = sender as FrameworkElement;
        if (fe != null)
        {
            CurrentPicture = fe.DataContext as Picture;
        }

but is null a datacontext because I used "Source".

how can I do?

1

1 Answers

0
votes

It depends on which event you've wired up. If you're handling the SelectionChanged event, you can retrieve the BitmapImage (not Picture) from the AddedItems collection in the SelectionChangedEventArgs event arguments parameter:

private void LongListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    if (e.AddedItems.Count > 0)
    {
        BitmapImage bmp = e.AddedItems[0] as BitmapImage;
    }
}

Alternatively if you're handling the Tap event of the Image element in the LongListSelector's ItemTemplate, then you can retrieve the BitmapImage from the sender parameter:

Image imgElement = sender as Image;
BitmapImage bmp = imgElement.Source as BitmapImage;