2013-11-15 87 views
0

我需要在LongListMultiSelector中顯示我的設備(WP8)中存在的所有照片。 我用這個方法WP8 MediaLibrary,查看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; 
     } 

,但空一個DataContext,因爲我使用的「源代碼」。

我該怎麼辦?

回答

0

這取決於您連接了哪個事件。如果你正在處理的圖像元素的點擊事件

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

另外:如果你正在處理SelectionChanged事件,您可以從AddedItems集合中的SelectionChangedEventArgs事件參數的參數檢索的BitmapImage(不圖) LongListSelector的ItemTemplate,那麼您可以從發件人參數中檢索BitmapImage:

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

謝謝我understead –