繁体   English   中英

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

[英]How to pass multiple data between pages in windows phone

在窗口电话中,我使用以下代码在页面之间传输数据,

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

这里我在页面之间传递一个对象,我应该怎么做才能在页面之间传递两个对象?

更新:

这个问题的答案是一个更好的解决方案:将数据从页面传递到页面

  • 码:

     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"]; 

您只需向URL添加参数,如下所示:

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

否则,创建一个包装所有对象的包装器对象(就像在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));

我不确定你的意思是什么。 您是指从Object继承的ACTUAL对象,还是指String值或int值等值。

而不管:

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

这应该适合你。

试着读一下

此外,您应该了解MVVM模式并尝试使用它! 关于MVVM,你可以在这里阅读

暂无
暂无

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

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