将光学图像从一页传递到另一页C#

我知道如何通过NavigationService.Navigate传递数据(new Uri(“/ Second.xaml?msg = mesage”,UriKind.Relative));

问题是,如何将从库中选择的图像传递到另一个页面?

要选择图像,我使用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; } } 

如何将所选照片发送到另一页?

您只能在查询字符串中传递字符串。 将图像源从一个页面传递到另一个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; }