[英]How to pass data between two pages in Windows Phone 8.1 application ?
I have a Windows phone 8.1 application where I have two pages displaying data. 我有一个Windows Phone 8.1应用程序,其中有两个页面显示数据。 The first page has a listview displaying all of the data from an sqlite database, and when the user taps on one item in the listview, the second page opens with a listview that contains more details about that specific record from the database.
第一个页面具有一个列表视图,显示来自sqlite数据库的所有数据,并且当用户点击列表视图中的一个项目时,第二个页面将打开一个列表视图,其中包含有关该数据库中特定记录的更多详细信息。 My question is how to achieve this in Windows Phone 8.1 using c# ?
我的问题是如何使用c#在Windows Phone 8.1中实现此目标?
in windows phone 8.1 there are two ways to do it: 在Windows Phone 8.1中,有两种方法可以实现:
void SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var list= sender as Listview;
var taped=list.SelectedItem as Model;
//here you send your parameter to the second page
Frame.Navigate(Typeof(SecondPage),taped);
}
or 要么
public static Model taped;
void SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var list= sender as Listview;
taped=list.SelectedItem as Model;
}
and in the SecondPage you can acces to it via FirstPage.taped; 在SecondPage中,您可以通过FirstPage.taped访问它;
On first page you should write something like this: 在第一页上,您应该这样写:
Frame.Navigate(typeof(SecondPage), someData);
For second page you should override OnNavigatedTo( NavigationEventArgs e ). 对于第二页,您应该重写OnNavigatedTo(NavigationEventArgs e)。 For example:
例如:
protected override void OnNavigatedTo( NavigationEventArgs e )
{
MyData data = e.Parameter as MyData.
}
Several options: 几种选择:
secondpage.xaml
, you could navigate to secondpage.xaml?param1=abc123¶m2=<base64 data>
. secondpage.xaml?param1=abc123¶m2=<base64 data>
,而不是导航至secondpage.xaml
。 You pick up the navigation parameter by overriding the onNavigatedTo
function, same as you would do for checking the parameters that an app was launched with (but not, presumably, on the start page). onNavigatedTo
函数来获取导航参数,就像检查应用程序启动时所用的参数一样(但可能不在起始页上)。 Note that this may be Silverlight-specific; App
class (as defined in App.xaml.cs
) that you read and write from other classes. App
类(在App.xaml.cs
定义)中添加一个公共字段。 You can add a static public field in any class, and read and write from it.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.