如何使用 Windows Phone 8 中的对象导航? [英] How to navigate with objects in windows phone 8?
问题描述
我需要使用对象而不是字符串从一个 xaml 页面导航到另一个页面 ..
I need to navigate from one xaml page to another with an Object not a String ..
目前的代码是:
private void Border_ManipulationStarted(object sender, System.Windows.Input.ManipulationStartedEventArgs e)
{
string uri = "/PhonePageOne.xaml?Text=";
uri += txtBox.Text;
NavigationService.Navigate(new Uri(uri, UriKind.Relative));
}
我不想在 url 中传递文本,我需要传递一个对象而不是像下面这样的对象,有什么方法可以做到这一点?
i dont want to pass a text in the url, i need to pass an object instead of that like below , and any way to do this ?
Person p = new person();
uri+=p
推荐答案
在第一页执行以下操作:
In the first page do the following:
PhoneApplicationService.Current.State["param"] = p;
NavigationService.Navigate(new Uri("/PhonePageOne.xaml", UriKind.Relative));
然后在第二次检索参数:
And in the second retrieve the parameter:
Person p = PhoneApplicationService.Current.State["param"] as Person;
PhoneApplicationService.State
字典是一个临时存储位置,它会一直存在,直到您的应用被停用.
The PhoneApplicationService.State
dictionary is a temporary storage location which persists until your app is deactivated.
其他选项可以是在例如 App.xaml.cs
中声明一个静态成员,并使用它来保存一个页面中的对象并从第二个页面中检索.
Other option could be to declare a static member in, for example, App.xaml.cs
and use it to save the object from one page and to retrieve from the second one.
这篇关于如何使用 Windows Phone 8 中的对象导航?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!