简体   繁体   中英

Page Navigation Windows Phone 8.1

Page Navigation in Windows Phone 8.1 is:

Frame.Navigate(typeof(SecondPage));

or with parameter:

Frame.Navigate(typeof(SecondPage), param);

and on the target page:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
  myTextBox.Text = e.Parameter.ToString();
}

or

protected override void OnNavigatedTo(NavigationEventArgs e)
{
  var val = (myClass)e.Parameter;
  myTextBox.Text = val.Text;
}

But in my case I want to do something with those data received on the target page. For example I want to let the user edit those data and save them as new data. I've searched for hours and all I could find was just page navigation with or without parameter and not the one I've described above. Is there any way to approach this? Any suggestion, solution is appreciated!

To pass your text and the settings name to your edit form, use a KeyValuePair:

//figure out how to get the text out of the list
var myItem = new KeyValuePair<string, string>("mytextsetting", "listbox.selecteditem.text");
Frame.Navigate(typeof(SecondPage), myItem);

On the second page, you can now store the incoming parameter:

KeyValuePair<string, string> _myItem;

protected override void OnNavigatedTo(NavigationEventArgs e)
{
   _myItem = e.Parameter as KeyValuePair<string, string>;
   myTextBox.Text = myItem.Value;
}

Now when the user wants to save the edited text:

_myItem.Value = myTextBox.Text;

//save it to the settings
localSettings.Values[_myItem.Key] = _myItem.Value;

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM