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

  • Home
  • SEARCH
  • 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 7444845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:35:59+00:00 2026-05-29T11:35:59+00:00

I have silverlight 4 application with PRISM 4, I’m using MEF. My Shell defines

  • 0

I have silverlight 4 application with PRISM 4, I’m using MEF.

My Shell defines one main region in which modules are loaded, I want modules to have their own RegionManager, so regions that they define are places in local RegionManager instead of global. And I want this local RegionManager to be resolved by container (for type IRegionManager) when inside the module.

However the method from documentation:

IRegion detailsRegion = this.regionManager.Regions["DetailsRegion"];
View view = new View();
bool createRegionManagerScope = true;
IRegionManager detailsRegionManager = detailsRegion.Add(view, null, 
                            createRegionManagerScope);

Doesnt work for me, when resolving IRegionManager from inside child view I still get GlobalRegionManager.

  • 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-29T11:36:00+00:00Added an answer on May 29, 2026 at 11:36 am

    I was in the same situation as you, I had a nested region manager, but all of the child views were still getting the global region manager. I came up with what I consider a reasonable solution.

    First I define an interface:

    /// <summary>
    /// An interface which is aware of the current region manager.
    /// </summary>
    public interface IRegionManagerAware
    {
        /// <summary>
        /// Gets or sets the current region manager.
        /// </summary>
        /// <value>
        /// The current region manager.
        /// </value>
        IRegionManager RegionManager { get; set; }
    }
    

    Then I setup a RegionBehavior like so:

    /// <summary>
    /// A behaviour class which attaches the current scoped <see cref="IRegionManager"/> to views and their data contexts.
    /// </summary>
    public class RegionAwareBehaviour : RegionBehavior
    {
        /// <summary>
        /// The key to identify this behaviour.
        /// </summary>
        public const string RegionAwareBehaviourKey = "RegionAwareBehaviour";
    
        /// <summary>
        /// Override this method to perform the logic after the behaviour has been attached.
        /// </summary>
        protected override void OnAttach()
        {
            Region.Views.CollectionChanged += RegionViewsChanged;
        }
    
        private void RegionViewsChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            Contract.Requires<ArgumentNullException>(e != null);
    
            if (e.NewItems != null)
                foreach (var item in e.NewItems)
                    MakeViewAware(item);
        }
    
        private void MakeViewAware(object view)
        {
            Contract.Requires<ArgumentNullException>(view != null);
    
            var frameworkElement = view as FrameworkElement;
            if (frameworkElement != null)
                MakeDataContextAware(frameworkElement);
    
            MakeAware(view);
        }
    
        private void MakeDataContextAware(FrameworkElement frameworkElement)
        {
            Contract.Requires<ArgumentNullException>(frameworkElement != null);
    
            if (frameworkElement.DataContext != null)
                MakeAware(frameworkElement.DataContext);
        }
    
        private void MakeAware(object target)
        {
            Contract.Requires<ArgumentNullException>(target != null);
    
            var scope = target as IRegionManagerAware;
            if (scope != null)
                scope.RegionManager = Region.RegionManager;
        }
    }
    

    Then apply this to all regions in your bootstrapper:

    protected override IRegionBehaviorFactory ConfigureDefaultRegionBehaviors()
    {
        var behaviours = base.ConfigureDefaultRegionBehaviors();
    
        behaviours.AddIfMissing(RegionAwareBehaviour.RegionAwareBehaviourKey, typeof(RegionAwareBehaviour));
    
        return behaviours;
    }
    

    Then all you have to do is implement IRegionManagerAware on your view/viewmodel, probably like so:

    public class MyView : IRegionManagerAware
    {
        IRegionManager RegionManager { set; get; }
    }
    

    Then when this view is added to a region, the behaviour will correctly set the RegionManager property to the currently scoped region manager.

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

Sidebar

Related Questions

The scenario: I have a PRISM application developed in Silverlight (4), and I'm using
In silverlight prism application I have a region (ContentControl) and would like to remove
I'm using PRISM in a SilverLight 4 application. I have a problem where views
we have developed an intranet application with Silverlight 4 using MVVM with PRISM. Up
In my solution, I have one application project, which defines all the resources -
I have a Silverlight application in which I would like to call a WCF
I have a Silverlight application which has on it a Canvas. On that Canvas,
I have a silverlight application which reads data from a db and displays them
I have a Silverlight application that is using a DataGrid. Inside of that DataGrid
I have Silverlight application using NHibernate as a ORM. I have projects for Data(mapp

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.