[英]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?? 这里我在页面之间传递一个对象,我应该怎么做才能在页面之间传递两个对象?
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: 您只需向URL添加参数,如下所示:
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): 否则,创建一个包装所有对象的包装器对象(就像在MVVM模式中使用的那样):
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));
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.
您是指从Object继承的ACTUAL对象,还是指String值或int值等值。
regardless: 而不管:
NavigationService.Navigate(new Uri("/Page.xaml?object1="+obj+"&object2="+obj2, UriKind.Relative));
This should work for you. 这应该适合你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.