Question

I have a WPF project based upon Prism Feb 2009 release set up as:

Shell exposes a single ContentControl as "MainRegion" Another view (user control) defined in the Infrastructure project called SplitView exposes two additional regions "LeftRegion" and "RightRegion" also as ContentControl.

Some of my application's modules need to display their view in the MainRegion (one user control), while others need to display their views (two user controls in a split fashion) in the LeftRegion and RightRegion.

I have tried using scoped regions, assuming that specific Controllers would hold references to the scoped regions. So basically each controller interested in SplitView functionality should instantiate a new SplitView (user control) and activate it in the MainRegion while activating its two user controls in the LeftRegion and RightRegion of the newly created scoped SplitView regions.

I am using MVVM with View Injection to display the views.

Needless to say, something has gone horrifically wrong with this approach.

At runtime I get this exception, "An exception occurred while creating a region with name 'LeftRegion'. The exception was: System.InvalidOperationException: Specified element is already the logical child of another element. Disconnect it first."

Am I correct at assuming that the LeftRegion and RightRegion are trying to register themselves with the main RegionManager every time I instantiate the SplitView?

Sorry about the confusing/verbose post. Any suggestions? Best practices to achieve this?

Thanks in advance,

Ali

Was it helpful?

Solution

The exception of "Specified element is already the logical child..." is what happens when you try to add something to two places in the tree, so I imagine there might be some logical error in your code, or you are adding something twice.

I generally create my sub regions like this:

    m_scopedRegionName = Guid.NewGuid().ToString(); /* EXAMPLE ! */
    m_scopedRegionManager =  m_regionManager.Regions[RegionNames.WORKSPACE_REGION].Add(myViewModel.View, m_scopedRegionName, true);
    m_someThingRegion = m_scopedRegionManager.Regions[RegionNames.SOME_THING_REGION];

Then I add any new stuff into the "m_someThingRegion".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top