简体   繁体   English

如何在Windows Phone中的页面之间传递多个数据

[英]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?? 这里我在页面之间传递一个对象,我应该怎么做才能在页面之间传递两个对象?

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: 您只需向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. 这应该适合你。

Try to read this 试着读一下

Also, you should learn about MVVM pattern and try to use it! 此外,您应该了解MVVM模式并尝试使用它! About MVVM you can read here 关于MVVM,你可以在这里阅读

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

相关问题 如何在Windows Phone 8.1应用程序的两个页面之间传递数据? - How to pass data between two pages in Windows Phone 8.1 application ? 如何在Windows Phone的页面之间传递照片? - How to pass a photo between pages in Windows Phone? 我如何在页面之间传递值? (Windows Phone) - How I can pass values between pages? (Windows Phone) 在Windows Phone中的页面之间导航时如何保留数据 - how to retain data while navigating between pages in windows phone 在Windows Phone 8页面之间将特殊字符作为字符串传递 - Pass special characters as string between Windows Phone 8 pages 在显示Null Phone 8.1 UAP的页面之间传递数据 - Pass Data Between Pages Showing Null Phone 8.1 UAP 如何在Windows Phone 8.1RT中的页面之间导航 - How to navigate between pages in windows phone 8.1RT 如何在不同的Windows Phone页面之间共享XAML代码? - How to share xaml code between different windows phone pages? 如何将数据存储在隐藏字段中并在剃刀页面中的页面之间传递 - How to store data in a hidden field and the pass it between pages in razor pages Windows Phone C#中的页面之间传递字符串值时,Navigation_Failed - Navigation_Failed when pass string value between pages in windows phone C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM