Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Implementing the Master-Detail pattern using pages

From: Windows Phone SDK Essential Training

Video: Implementing the Master-Detail pattern using pages

The final part of our examination of the Windows Phone Databound template, we're going to look at how the master-detail pattern is implemented using Windows Phone pages. Come back to our code again. We looked at this briefly before. The key is to look at the MainListBox_SelectionChanged event handler. When the user taps an item in the list box, the SelectionChanged event is fired, this method gets called, and we First of all, make sure that the selected index has some value.

Implementing the Master-Detail pattern using pages

The final part of our examination of the Windows Phone Databound template, we're going to look at how the master-detail pattern is implemented using Windows Phone pages. Come back to our code again. We looked at this briefly before. The key is to look at the MainListBox_SelectionChanged event handler. When the user taps an item in the list box, the SelectionChanged event is fired, this method gets called, and we First of all, make sure that the selected index has some value.

Sometimes this event gets fired on un-selections, in other words, you select something, and then you do something else and the event will get fired again, but there won't actually be an item selected. So you put a guard here to make sure that that's the case because you don't want to navigate to your detail page if there is no actual selection. The way the master and detail is set up is that the detail page is basically capable of displaying any one of those ItemViewModel data objects. So what we do is we use the page navigation service to say we want to navigate to the details page, and because Silverlight has a history from a web environment, it uses URIs and query parameters similar to the way you would if you were doing web pages.

So in this particular case, we create a query item of the name selectedItem, and we pass it the SelectedIndex from the MainListBox. When we get to the detail page, you'll see that the detail page will take this index, go back to the MainViewModel, and extract the individual item that we want. Finally, when the user taps on the screen to select an item, it will highlight in whatever the current theme color is for the phone, but you want the highlight to turn off so that when the user comes back to the page, there's no item selected.

So in order to do that, we set the SelectedIndex of the MainListBox equal to -1. So this is how we start. Let's go to the detail page and see what happens when we get there. Here on the DetailPage, we'll see the main constructor, and we'll see a common method that you'll use when you have multi- page applications which require parameters. In this case, you use the OnNavigatedTo method. So we start out by saying let's figure out what our selectedIndex is then we go to the NavigationContext which is a class associated with this page, we retrieve the QueryString, and we use TryGetValue to see if we can get a query parameter called selectedItem.

The reason we do that is because if someone writes code navigates to this page and they don't put the query string on, we might want to do something else. Notice that the result of TryGetValue is always a string, so if we do get the value for selectedItem, the first thing we have to do is to parse it back into an integer so now we have an index, and then we set the data context for this details page equal to the App.ViewModel.Items of that specific index. And to see how it actually gets displayed, let's take a look at the XAML, and we see two things.

One, we haven't yet changed the name of our application on this page, that's something you have to do on every single page. It's not something that you can change once and have it cascade all the way through. So we're going to come up here and say again, Edit > Advanced > Format Document, change the text here to SONNETS. You'll notice that we're not going to change the name of the page because we have a different thing. We have a TextBlock which has a ListTitle, and that's going to be replaced by the LineOne of our ItemViewModel instance.

So in this case, it will be the number of the sonnet. That's all we have to look at for how we implemented the master-detail pages so far. When the user is done, they click the Back button and go back to the list of the sonnets, and there's no selection in the list box and they can try again. So let's move on in the next movie to actually loading our sonnets in and getting it to display instead of the sample data.

Show transcript

This video is part of

Image for Windows Phone SDK Essential Training
Windows Phone SDK Essential Training

65 video lessons · 3042 viewers

Michael Lehman
Author

 
Expand all | Collapse all
  1. 2m 34s
    1. Welcome
      55s
    2. What you need to know to take this course
      51s
    3. Using the exercise files
      48s
  2. 15m 44s
    1. Downloading and installing the Windows Phone tools
      2m 44s
    2. Creating a Hello World application
      9m 31s
    3. Debugging on a Windows Phone device
      3m 29s
  3. 6m 29s
    1. Exploring device capabilities
      2m 58s
    2. Understanding the Emulator
      3m 31s
  4. 8m 51s
    1. Understanding the SDK
      8m 51s
  5. 41m 32s
    1. Introducing the converter
      3m 36s
    2. Creating the user experience (UX)
      13m 35s
    3. Responding to the Application Bar
      2m 40s
    4. Implementing click handlers
      3m 52s
    5. Saving and loading settings
      8m 18s
    6. Preparing your app for shipment
      9m 31s
  6. 20m 48s
    1. Introducing sonnets
      1m 38s
    2. Data binding with Silverlight
      4m 4s
    3. Exploring the Model-View-ViewModel pattern (MVVM)
      4m 2s
    4. Implementing the Master-Detail pattern using pages
      3m 53s
    5. Loading external data
      7m 11s
  7. 50m 26s
    1. Choosing a multipage controller
      3m 13s
    2. Preparing for persistence
      7m 30s
    3. Updating the data model
      7m 2s
    4. Creating the details page
      4m 30s
    5. Bringing it all together
      3m 58s
    6. Cloning a Windows Phone app
      6m 49s
    7. Using SQL CE
      8m 49s
    8. Updating the data model
      2m 24s
    9. Querying and updating the database
      6m 11s
  8. 14m 19s
    1. Working with the camera
      6m 11s
    2. Exploring GPS
      5m 21s
    3. Exploring the accelerometer
      2m 47s
  9. 29m 34s
    1. Introducing recording and playback with XNA
      45s
    2. Capturing sound
      5m 12s
    3. Providing feedback while recording
      5m 50s
    4. Playing a recording
      4m 34s
    5. Persisting a recording
      2m 58s
    6. Listing recordings
      5m 15s
    7. Managing the recording list
      3m 26s
    8. Recording under the lock screen
      1m 34s
  10. 28m 32s
    1. Building the UX
      3m 54s
    2. Using WebClient
      4m 1s
    3. Determining network connectivity
      2m 9s
    4. Leveraging Internet Explorer
      7m 56s
    5. Adding a live tile
      2m 42s
    6. Building a background agent
      7m 50s
  11. 14m 46s
    1. Hello World in C++
      4m 35s
    2. Libraries
      4m 17s
    3. Managed plus managed
      5m 54s
  12. 26m 35s
    1. Exploring built-in controls
      4m 28s
    2. Windows Phone Toolkit
      2m 42s
    3. Introducing Coding4Fun
      3m 13s
    4. Reminders and notifications
      6m 10s
    5. Wallet and In-App Purchase
      1m 34s
    6. File and protocol associations
      1m 59s
    7. Bluetooth
      44s
    8. Integrating speech
      1m 28s
    9. Near field communication (NFC)
      1m 23s
    10. WinRT and legacy Windows Phone APIs
      2m 54s
  13. 12m 14s
    1. Publishing your apps
      2m 49s
    2. Learning from apps in the Windows Phone Marketplace
      1m 22s
    3. Staying in touch with updates and new information from Microsoft
      2m 34s
    4. Looking at Windows Phone 7 app reviews
      44s
    5. Exploring web sites books and other useful links
      4m 45s
  14. 1m 34s
    1. Farewell
      1m 34s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Windows Phone SDK Essential Training.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.