2

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??

Aju
  • 796
  • 3
  • 10
  • 29

3 Answers3

13

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));
Community
  • 1
  • 1
Abbas
  • 14,186
  • 6
  • 41
  • 72
2

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.

DotNetRussell
  • 9,716
  • 10
  • 56
  • 111
  • You only can pass strings between pages in this way. Use PhoneApplicationService.Current.State["MyObject"] to save any object you would like to pass. – Tealc Wu Dec 29 '14 at 07:17
-1

Try to read this

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

Vitaliy
  • 485
  • 1
  • 5
  • 22