Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Phone Navigation - Passing back to the page before

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

like image 530
user1290653 Avatar asked Jan 19 '26 21:01

user1290653


2 Answers

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.

//App.xaml.cs
int datafield ;

//Page1xaml.cs
(App.Current as App).dataField =10;

//Page2.xaml.cs
int x =  (App.Current as App).dataField 
like image 194
TutuGeorge Avatar answered Jan 21 '26 09:01

TutuGeorge


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 :-

public class MyManager
{
    private static MyManager _instance;

    public static MyManager Instance
    {
        get
        {
            if (_instance == null)
            {
                _instance = new MyManager();
            }
            return _instance;
        }
    }
}
like image 31
Paul Diston Avatar answered Jan 21 '26 11:01

Paul Diston