C# C在WindowsPhone中将select上的图像从一个页面传递到另一个xaml页面

C# C在WindowsPhone中将select上的图像从一个页面传递到另一个xaml页面,c#,.net,xaml,windows-phone-7,C#,.net,Xaml,Windows Phone 7,使用Photochooser任务,图像必须加载并立即传递到另一个页面。但在实现以下代码时显示为空: private void LoadPicture_Click(object sender, RoutedEventArgs e) { PhotoChooserTask photoChooserTask; photoChooserTask = new PhotoChooserTask(); photoChooserTask.Completed += new EventHand

使用Photochooser任务,图像必须加载并立即传递到另一个页面。但在实现以下代码时显示为空:

private void LoadPicture_Click(object sender, RoutedEventArgs e)
{
    PhotoChooserTask photoChooserTask;
    photoChooserTask = new PhotoChooserTask();
    photoChooserTask.Completed += new EventHandler<PhotoResult>(photoChooserTask_Completed);
    photoChooserTask.Show();

    NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative));
}

void photoChooserTask_Completed(object sender, PhotoResult e)
{
    if (e.TaskResult == TaskResult.OK)
    {
        System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
        bmp.SetSource(e.ChosenPhoto);

        Page1 p1 = new Page1();
        p1.encodeImg.Source = bmp;
    }
    else
    {
        MessageBox.Show("Image Loading Failed.");
    }
}
请在修复上述问题时提出建议


谢谢

你解决了吗?如果你没有,你可以用这样的东西。在photoChooseTask处理程序中保存位图图像

 PhoneApplicationService.Current.State["yourparam"] = bmp;
BitmapImage bitmapGet = PhoneApplicationService.Current.State["yourparam"] as BitmapImage;
然后在第1页中,您会看到位图图像

 PhoneApplicationService.Current.State["yourparam"] = bmp;
BitmapImage bitmapGet = PhoneApplicationService.Current.State["yourparam"] as BitmapImage;
下面是你应该如何使用这个

void photoChooserTask_Completed(object sender, PhotoResult e)
    {
        if (e.TaskResult == TaskResult.OK)
        {
            System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
            bmp.SetSource(e.ChosenPhoto);
            //save the bitmapImage 
            PhoneApplicationService.Current.State["yourparam"] = bmp;


        }
        else
        {
            MessageBox.Show("Image Loading Failed.");
        }


        NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative));
    }
你的页面1

      protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
      {
           //get the bitmapImage
           BitmapImage bitmapGet = PhoneApplicationService.Current.State["yourparam"] as BitmapImage;

           //set the bitmpaImage 
           img.Source = bitmapGet;

           base.OnNavigatedTo(e);
      }

导航必须在事件完成后完成,photochooser.show会抑制主应用程序线程,因此您只能在获得图像流后传递它。因此,将导航语句转换为已完成的事件处理程序,并使用isolatedstoragesettings.applicationsettings来存储图像并将其返回到第二页。

另一种实现方法是先将图像保存在IsolatedStorage中,然后将文件路径作为字符串参数传递给page1


page1可以在需要时随时加载图像。

您是否尝试通过ctor?新网页1BMP;page1和page1.xaml真的是同一页吗?这可能是两个不同的例子。是的,它们是一样的。我打错了。但它们都是一样的。为第1页p1=新的第1页;