[Win10 Development] How to pass values between pages, win10 Development page

Source: Internet
Author: User

[Win10 Development] How to pass values between pages, win10 Development page

We know that UWP uses different pages to display different content. How do we transmit values between pages?

First, we will write a ListView in MainPage to display some English words.

 1         List<English> wordList = new List<English> 2         { 3             new English { Word = "absolutely",}, 4             new English { Word = "acceleration"}, 5             new English { Word = "acceptance"}, 6             new English { Word = "accessory"}, 7             new English { Word = "accidental"}, 8             new English { Word = "accommodate"}, 9             new English { Word = "accord"},10             new English { Word = "accordance"},11             new English { Word = "accordingly"},12             new English { Word = "accumlate"},13             new English { Word = "accustom"},14         };15         ...16         ...17     public class English18     {19         public string Word { get; set; }20     }

Then, bind the data to the control.

1 list.ItemsSource = wordList;

Next, we will focus on clicking an item of ListView and navigate to another page to display the selected items. The Navigate method is required for page navigation. Its first parameter is the next page to be navigated, and the second parameter is the value passed to the next page. Let's take a look at the specific code.

1         private void list_ItemClick(object sender, ItemClickEventArgs e)2         {3             this.Frame.Navigate(typeof(SelectWord),(e.ClickedItem as English).Word);4         }

When you navigate to the next page, the value is also passed. How can I accept this value on the next page?

We need to rewrite the OnNavigatedTo method. Its parameter is the value we need. Let's look at the code.

1         protected override void OnNavigatedTo(NavigationEventArgs e)2         {3             select.Text = e.Parameter.ToString();4             base.OnNavigatedTo(e);5         }

At this time, we get the passed value and display it to the second page. Is it easy?

Finally, let's take a look at the effect.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.