I would like to click on a button to take me to a page , then click on a listbox item, click on a button on the new page and pass it back to the page before without creating a new URI of the first page.
**First Page**
private void btnAddExistingMember_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/ChooseMember.xaml", UriKind.Relative));
}
**Second page after choosing listbox value**
private void btnAddSelected_Click(object sender, RoutedEventArgs e)
{
Member currMember = (Member)lstMembers.SelectedItem;
string memberID = currMember.ID.ToString();
//navigate back to first page here passing memberID
}
can it be done?
Thank you
You could create a manager class that would hold the member id. This manager class could then be accessed from both your first page and ChooseMember page.
An example of a Singleton Manager class :-
I found a solution at codeproject which was quite useful to me.
While moving from the second form, save your data in
PhoneApplicationService.Current.State
Go back using same
NavigationService.GoBack();
and inOnNavigatedTo
method, fetch the following code.References:
MSDN: PhoneApplicationService Class
Original Solution at: How to pass values between pages in windows phone
You can store the member in the App.xaml.cs file. This is common file accesssible for all files in the application. This works like a global variable.
Sounds to me like you want to set some object as the context for another page. Messaging in MVVM Light sounds like a good solution for this. Doesn't look like you're using MVVM so this may not be immediately applicable. This post pretty much lays out what I'm saying here.
Second Page
Create your SelectedObject property and make sure to call
The last parameter
true
says to broadcast this change in value to anyone listening. You'll need to wire up some other commands for listbox selected item and button click etc, but I won't go into that here since it's not directly related to your question. Selecting the Listbox item will simply set the data item for the first page like you want to accomplish. The button click can deal with the navigation.First Page
In your view model constructor, register to receive the change broadcasted from Second Page
then define UpdateObject
You can simply use