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

Aju*_*Aju 2 c# windows-phone-7

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

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

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

Abb*_*bas 13

更新:

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

  • 码:

    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"];
    
    Run Code Online (Sandbox Code Playgroud)

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

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

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