简体   繁体   中英

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? As For passing string or int values we use querystring.Can we do the same for passing the object:-

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 }

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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