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

时间:2014-03-19 06:30:22

标签: c# windows-phone-8

我知道如何通过NavigationService.Navigate传递数据(新的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;
        }
    }

如何将所选照片发送到其他页面?

1 个答案:

答案 0 :(得分: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;
    }