I have a Windows phone 8.1 application where I have two pages displaying data. 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. My question is how to achieve this in Windows Phone 8.1 using c# ?
in windows phone 8.1 there are two ways to do it:
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;
On first page you should write something like this:
Frame.Navigate(typeof(SecondPage), someData);
For second page you should override 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>
. 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). Note that this may be Silverlight-specific; I haven't tried it with non-Silverlight apps. App
class (as defined in App.xaml.cs
) that you read and write from other classes. You can add a static public field in any class, and read and write from it. Globals are considered a bad design, but sticking them on the specific classes that are supposed to access them is reasonable. Note that different pages might sometimes be processed on different threads.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.