0

デバイス (WP8) にあるすべての写真を LongListMultiSelector に表示する必要があります。私はこの方法を使用します

 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;

XAMLでは、この画像設定があります

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

それはすべて完璧に機能しますが、いくつか質問があります。

単一の画像をズームしたいのですが、画像タップでこのコードを挿入します

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

「ソース」を使用したため、データコンテキストはnullです。

どのようにできるのか?

4

1 に答える 1

0

それは、配線したイベントによって異なります。SelectionChanged イベントを処理している場合は、SelectionChangedEventArgs イベント引数パラメーターで、AddedItems コレクションから BitmapImage (Picture ではなく) を取得できます。

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

または、LongListSelector の ItemTemplate で Image 要素の Tap イベントを処理している場合は、sender パラメータから BitmapImage を取得できます。

Image imgElement = sender as Image;
BitmapImage bmp = imgElement.Source as BitmapImage;
于 2013-11-16T01:27:44.260 に答える