简体   繁体   English

在wp8中将对象从一页传递到另一页

[英]Pass object from one page to another in wp8

If I have to pass an object from one page to another in wp8.What should be done? 如果我必须在wp8中将对象从一页传递到另一页,应该怎么办? As For passing string or int values we use querystring.Can we do the same for passing the object:- 对于传递字符串或int值,我们使用querystring。我们可以为传递对象做同样的事情:-

Vehicle vm = item as Vehicle; NavigationService.Navigate(new Uri("/Page2.xaml?values=" + vm, UriKind.Relative));

and in the other class:- 在另一类中:

var values1=""; if (NavigationContext.QueryString.TryGetValue("values", out values1)) var values1=""; if (NavigationContext.QueryString.TryGetValue("values", out values1)) { //do something with the parameter } var values1=""; if (NavigationContext.QueryString.TryGetValue("values", out values1)) { //do something with the parameter }

To pass non string Data, you can do something like this, 要传递非字符串数据,您可以执行以下操作,

 public static void Navigate(this NavigationService navigationService, Uri source, object data)
    {
        Data = data;
        navigationService.Navigate(source);
    }

Here is the extension methods of the NavigationService: 这是NavigationService的扩展方法:

public static class Extensions
    {
        private static object Data;


        public static void Navigate(this NavigationService navigationService, Uri source, object data)
        {
            Data = data;
            navigationService.Navigate(source);
        }

        public static object GetNavigationData(this NavigationService service)
        {
            return Data;
        }
    }

You can follow this link : 您可以点击以下链接:

How to pass a complex object to a page

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM