从一个页面传递photochosen图像到另一个C# [英] pass photochosen image from one page to another C#

查看:120
本文介绍了从一个页面传递photochosen图像到另一个C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何通过NavigationService.Navigate(新的URI(/ Second.xaml味精= mesage?,UriKind.Relative))将数据传递;

I know how to pass data through NavigationService.Navigate(new Uri("/Second.xaml?msg=mesage", UriKind.Relative));

问题是,我怎么能传递从库中选择到另一页图片?

The question is, how can I pass an image selected from the library to another page?

要选择一个图像,我用的是PhotoChooserTask,并在那里完成我的事件有这样的:

To select an image, I use the PhotoChooserTask and in the event where it is completed I have this:

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



我如何发送所选照片到另一个页面?

How can I send the chosen photo to another page?

推荐答案

您只能在查询字符串传递字符串。从一个页面传递图像源到另一个PhoneApplicationservice是最简单的方法。下面是简单的例子,从一个页面传递图像到另一个。

You can only pass string in Query String. To pass an image source from one page to another PhoneApplicationservice is easiest way. Here is the simple example to pass image from one page to another.

 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;
    }

这篇关于从一个页面传递photochosen图像到另一个C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆