2014-03-19 119 views
2

我知道如何通過NavigationService.Navigate傳遞數據(new Uri(「/ Second.xaml?msg = mesage」,UriKind.Relative));將photochosen圖像從一個頁面傳遞到另一個頁面C#

問題是,如何將從庫中選擇的圖像傳遞到另一頁?

要選擇圖像,我用它完成PhotoChooserTask和事件我有這樣的:

private void photoChooserTask_Completed(object sender, PhotoResult e) 
    { 
     if (e.ChosenPhoto != null) 
     { 
      BitmapImage image = new BitmapImage(); 
      image.SetSource(e.ChosenPhoto); 
      this.img.Source = image; 
     } 
    } 

我怎麼能選擇的照片發送到另一個頁面?

回答

3

您只能在查詢字符串中傳遞字符串。將圖像源從一個頁面傳遞到另一個PhoneApplicationservice是最簡單的方法。以下是將圖像從一個頁面傳遞到另一個頁面的簡單示例。

private void photoChooserTask_Completed(object sender, PhotoResult e) 
     { 
      if (e.ChosenPhoto != null) 
      { 
      **//Edits** 
      if (PhoneApplicationService.Current.State.ContainsKey("Image")) 
        if (PhoneApplicationService.Current.State["Image"] != null) 
         PhoneApplicationService.Current.State.Remove("Image"); 
       BitmapImage image = new BitmapImage(); 
       image.SetSource(e.ChosenPhoto); 
       this.img.Source = image; 
    PhoneApplicationService.Current.State["Image"] = image; 
      } 
     } 

//On second page 
//I assume you want to image on page load 
protected override void OnNavigatedTo(NavigationEventArgs e) 
    { 
     BitmapImage image = new BitmapImage(); 
    image =(BitmapImage)PhoneApplicationService.Current.State["Image"] 
    PhoneApplicationService.Current.State.Remove("Image"); 
    this.img.Source = image; 
    } 
+0

我已經試過你的代碼,但它給出錯誤「的導航已經失敗;中斷到調試」 System.Diagnostics.Debugger.Break(); –

+0

您在OnNavigatedTo事件或photoChooserTask_Completed事件上發生錯誤的位置? – Jaihind

+0

photoChooserTask_Completed –

相關問題