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

The Archive Base Latest Questions

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

How do we inject IRegionManager in the ViewModel using MEF Container. I have to

  • 0

How do we inject IRegionManager in the ViewModel using MEF Container. I have to switch view in my ViewModel’s Command delegate. Here is the brief description of what I am doing. I have an entity called Product whose list is displayed in one View (ProductListView). In that view the user can select the Product and click on Edit button. This would switch the view and present a new View(ProductEditView). For activating a different view, I would need a reference to IRegionManager something like this

public class ProductListVM : NotificationObject { //The Product List View Model
    [Import]
    public IRegionManager RegionManager { get; set; }

    private void EditProduct() { //EditCommand fired from ProductListView
        IRegion mainContentRegion = RegionManager.Regions["MainRegion"];
        //Switch the View in "MainContent" region.
        ....
    }
}

The above code fails with NullReferenceException for RegionManager. This seems logical because the above View Model is constructed by WPF through DataContext property in Xaml and DI doesn’t come into play, so it doesn’t get a chance to import the RegionManager instance. How do we resolve the IRegionManager in this scenario.

  • 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-31T19:36:16+00:00Added an answer on May 31, 2026 at 7:36 pm

    The Container instance can be exported in the bootstrapper using following

        container.ComposeExportedValue<CompositionContainer>(container);
    

    Then in the viewmodel, the IRegionManager instance can be imported using the code

        IServiceLocator serviceLocator = ServiceLocator.Current;
        CompositionContainer container = serviceLocator.GetInstance<CompositionContainer>();
        RegionManager = container.GetExportedValue<IRegionManager>();
    

    However, referring a View in ViewModel is a violation of the MVVM pattern. But since I was following an article here to learn Prism , I had to get along the same. Also the article was in Silverlight and I had to find a way to import RegionManager in wpf, which is little different.

    regards,
    Nirvan.

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

Sidebar

Related Questions

I'm using python-inject , python 2.6 (with unittest2). We have classes to test that
I'm trying to inject java enum through spring context using <util:constant . Here's what
Is is possible to inject IPrincipal using Castle Windsor into my asp.net mvc controller.
Is it possible to inject ejb's into pojo's using the @EJB annotation? If it
Is it possible to inject an instance of logger class object using Managed Extensibility
I want to inject the current namepace on my snippet. Does anyone have an
Sometimes SQL Inject queries may come in a disguise by using a different character
I try to inject the exception to thread using signals, but some times the
I am trying to inject cache to a module using module.config.php with no luck.
Can I inject a CSS file programmatically using a content script js file? It

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.