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 8539599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:24:13+00:00 2026-06-11T11:24:13+00:00

I’m building a Silverlight 5 application using MVVM light and I’m attempting to implement

  • 0

I’m building a Silverlight 5 application using MVVM light and I’m attempting to implement Navigation.

In the Silverlight 4 sample that Laurent builds during his Mix 11 talk (which targets SL4) he uses the following code to check if the SimpleIOC container contains an appropriate ViewModel and create one if it doesn’t already exist. The Navigation service is then called using said ViewModel.

if (!SimpleIoc.Default.Contains<NewsItemViewModel>(item.Link.ToString()))
{
    SimpleIoc.Default.Register(
    () => new NewsItemViewModel
    {
       Model = item
                },
       item.Link.ToString());
    }

        _navigationService.NavigateTo(
            new Uri(
                string.Format(ViewModelLocator.NewsItemUrl, item.Link),
                UriKind.Relative)); 

The following code is then executed in the NewsItemView’s OnNavigatedTo method which checks if the NewsItemViewModel exists (which it should, as it was just created) and then pulls it out of the container.

if (DataContext == null)
{
    var url = e.Uri.ToString();
    var itemUrl = url.Substring(url.IndexOf("?") + 1);

    if (!SimpleIoc.Default.Contains<NewsItemViewModel>(itemUrl))
    {
        MessageBox.Show("Item not found");
        return;
    }

    var vm = SimpleIoc.Default.GetInstance<NewsItemViewModel>(itemUrl);
    DataContext = vm;
}

When I attempt to do the same thing in a Silverlight 5 (doing pretty much an exact port of the project) I notice that the SimpleIoc.Default.Contains method does not exist, but a similar ContainsCreated(string key) does exist.

When I attempt to use this new method, the bool check always returns false and as a result the navigation fails (I get the “Item Not Found” message box).

An example of how I have rewritten the offending line is below

if (!SimpleIoc.Default.ContainsCreated<NewsItemViewModel>(itemUrl))

what am I missing here? Any help would be fantastic!

Kris

  • 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-06-11T11:24:15+00:00Added an answer on June 11, 2026 at 11:24 am

    How about using

    SimpleIoc.Default.IsRegistered<NewsItemViewModel>(itemUrl)
    

    I’ve been using just GetInstance(key) which creates it if not already created, but it first needs to have been registered, which the above will confirm.

    Although you may or may not want to use the key – as that checks for the type and key combination, but I think that as long as

    SimpleIoc.Default.IsRegistered<NewsItemViewModel>()
    

    returns true, then you should then be able to use GetInstance with the key

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a silverlight application using MVVM pattern but I don't understand what
Currently I'm building an application using latest Prism for Silverlight 4. I've a module
My team is building our first significant Silverlight application, using a 3 layered architecture
We're building an application that is a Silverlight client application, but we've created an
I'm building a windows phone 7 application using silverlight 4. I store my data
I'm building an application with a Silverlight frontend that communicates with a backend service
I'm building Silverlight applicaitions using Prism and MVVM. When calling WCF services on your
I'm building an application on Phone 7 using Silverlight and need to maintain some
I'm building a Silverlight application that interfaces with SharePoint Web Services. In a windows
we are currently building our first large application with Silverlight 4 (using PRISM) and

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.