title: C# Navigating Between Pages Without losing Data
body: <p>One of my assignments is to pass data to another page which I understand. But how do I get the data to stay when I go back to the Page?  Can someone explain how this works.</p>
  
  <pre><code> public sealed partial class MainPage : Page
      {
         string userName;
         public MainPage()
       {
  
          this.InitializeComponent();
      }
  
      private void btnPage2_Click(object sender, RoutedEventArgs e)
      {
          Frame.Navigate(typeof(Page2) ,  userName);
      }
  
      private void btnName_Click(object sender, RoutedEventArgs e)
      {
          userName = Convert.ToString(txtname.Text);
      }
  }
  </code></pre>