Aju
Aju

Reputation: 806

How to pass multiple data between pages in windows phone

In window phone, i use the following code to transfer data between pages,

NavigationService.Navigate(new Uri("/Page.xaml?object1=" & obj, UriKind.Relative));

Here i'm passing one object between pages, what should i do to pass two objects between pages??

Upvotes: 2

Views: 7832

Answers (3)

Abbas
Abbas

Reputation: 14432

Update:

The answer of this question is a better solution: Passing data from page to page

  • Code:

    PhoneApplicationService.Current.State["MyObject"] = yourObject;
    NavigationService.Navigate(new Uri("/view/Page.xaml", UriKind.Relative));
    
    //In the Page.xaml-page
    var obj = PhoneApplicationService.Current.State["MyObject"];
    

You can just add parameters to the URL, like this:

NavigationService.Navigate(new Uri("/Page.xaml?object1=" + obj + "&object2=" + obj2, UriKind.Relative));

Otherwise, create a wrapper object that holds all of your object (like used in the MVVM pattern):

public class Container
{
    public object Object1 { get; set; }
    public object Object2 { get; set; }
}

var container = new Container { Object1 = obj, Object2 = obj2 };
NavigationService.Navigate(new Uri("/Page.xaml?object1=" + container, UriKind.Relative));

Upvotes: 13

Vitaliy
Vitaliy

Reputation: 485

Try to read this

Also, you should learn about MVVM pattern and try to use it! About MVVM you can read here

Upvotes: -1

DotNetRussell
DotNetRussell

Reputation: 9857

Im not sure what you mean by object. Do you mean an ACTUAL object that inherits from Object or do you mean a value such as String value or int value.

regardless:

NavigationService.Navigate(new Uri("/Page.xaml?object1="+obj+"&object2="+obj2, UriKind.Relative));

This should work for you.

Upvotes: 2

Related Questions