Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6343819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:31:14+00:00 2026-05-24T20:31:14+00:00

I’m just switching a project across to mvvmlight and trying to do things the

  • 0

I’m just switching a project across to mvvmlight and trying to do things “the right way”

I’ve got a simple app with a listbox

When an item is selected in the listbox, then I’ve hooked up a RelayCommand

This RelayCommand causes a call on an INavigationService (http://geekswithblogs.net/lbugnion/archive/2011/01/06/navigation-in-a-wp7-application-with-mvvm-light.aspx) which navigates to a url like “/DetailPage.xaml?DetailId=12”

The DetailPage.xaml is then loaded and … this is where I’m a bit unsure…

  • how should the DetailPage get hooked up to a DetailView with DetailId of 12?
  • should I do this in Xaml somehow using a property on the ViewLocator?
  • should I do this in the NavigatedTo method?

Please feel free to point me to a full sample – sure this has been done a (hundred) thousand times before, but all the blogs and tutorials seem to be skipping this last trivial detail (focussing instead on the messaging and on the ioc on on the navigationservice)

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:31:16+00:00Added an answer on May 24, 2026 at 8:31 pm

    The only place you can retrieve the URL parameter is in the view. So since your view is likely depending on it, you should fetch it in the OnNavigatedTo method.

    Then, you should pass it along to your viewmodel, either using messaging (to expensive if you ask me), or by referring to your datacontext (which is the viewmodel I presume), and execeuting a method on that.

    private AddTilePageViewModel ViewModel
    {
        get
        {
            return DataContext as AddTilePageViewModel;
        }
    }
    
    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        var postalCode = NavigationContext.TryGetKey("PostalCode");
        var country = NavigationContext.TryGetStringKey("Country");
    
        if (postalCode.HasValue && string.IsNullOrEmpty(country) == false)
        {
            ViewModel.LoadCity(postalCode.Value, country);
        }
    
        base.OnNavigatedTo(e);
    }
    

    I’m using some special extensions for the NavigationContext to make it easier.

    namespace System.Windows.Navigation
    {
        public static class NavigationExtensions
        {
            public static int? TryGetKey(this NavigationContext source, string key)
            {
                if (source.QueryString.ContainsKey(key))
                {
                    string value = source.QueryString[key];
    
                    int result = 0;
                    if (int.TryParse(value, out result))
                    {
                        return result;
                    }
                }
    
                return null;
            }
    
            public static string TryGetStringKey(this NavigationContext source, string key)
            {
                if (source.QueryString.ContainsKey(key))
                {
                    return source.QueryString[key];
                }
    
                return null;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.