This project has moved and is read-only. For the latest updates, please go here.

Add/Remove Views from One region to another

Nov 1, 2011 at 8:18 AM
Edited Nov 1, 2011 at 2:52 PM


While using Jounce in my application, i have registered Exported "ViewA" inside a "ControlA".

On some user action, I need to UnRegister the "ViewA" from "ControlA" and add the same to "ControlB".

Basically i should unregister a View from it's current RegionManager control and register that particular view to some other RegionManager control with the state getting maintained(as a Shared View).

Please let me know how to do this through Jounce.

NOTE: i tried with ContentControl Adoptor provided as part of Jounce and it throws error "Value does not fall within the expected range"

if i try with ItemsControl adoptor, it's even worse, the Whole Screen goes for a toss. A blank white screen is getting displayed.

Is that got something to do with thread/dispatcher etc., Please provide your valuable comments.

Thanks as always,

Nov 3, 2011 at 10:13 PM

That's very straightforward with Jounce. You can simply provide a custom region adapter, or write an extension to the existing one, that listens for the deactivate navigation event. When you need to move the control, raise the deactivate event and have the region manage remove it from its children. The activate event will automatically place it back so no need to customize that side of the equation.

Nov 4, 2011 at 8:18 AM
Edited Nov 4, 2011 at 8:19 AM

Thanks Jeremy.

What i did before seeing your reply is, write an UnRegister region method in the corresponding RegionAdapter class and call it in the deactivate event in every UserControl.

The proposed solution by you would looks more sensible as i dont need to do it explicitly in every UserControl.

Will try out the same.

I really admire the extensibility Jounce provides for developers :)

Oct 5, 2012 at 11:06 AM
jeremylikness wrote:

have the region manage remove it from its children.

Hi Jeremy,

Please can you expand on what you mean by having the region manager remove a control from its children?  I'm trying to do the same thing as gbharathkumar, but from what I can see, you need to remove the control from _fluentViews, which is private.  I expect I've misunderstood something, but what?


Oct 6, 2012 at 10:09 AM

To remove a view you would raise the ViewNavigationArgs event but with Deactivate set true

EventAggregator.Publish(new ViewNavigationArgs(viewType) {Deactivate=true} );

Oct 8, 2012 at 9:23 AM

But that doesn't remove the control from _fluentViews, so you still get an ArgumentException thrown trying to add it again when you export the view to another region.  As far as I can see, DeactivateControl on the region manager boils down to ValidateControlName, which throws an exception if the control name is not valid, and does nothing otherwise.  Am I missing something?

Oct 12, 2012 at 12:44 PM

The situation as I see it is this: I import IFluentRegionManager and call ExportViewToRegion("myView", "myRegion1"), then I publish ViewNavigatedArgs and activate the view.  So far, so good.  The view appears in the region and behaves as I would expect.  When I want to reuse the view in another region, I publish the deactivate event, handle that in the RegionAdapter and remove the view from the region.  Next, I want to export the view to the new region - RegionManager.ExportViewToRegion("myView", "myRegion2");

Now, ExportViewToRegion consists of a single line:  _fluentViews.Add(viewName, regionTag);  At this point, you get an ArgumentException thrown, due to the key collision when you try to add the view again with a different region tag.  _fluentViews is private to the RegionManager, and there are no public methods which enable you to remove or modify entries.  I can't see any way round this.  Has anybody made it work?  gbharathkumar, did you get there?

Thanks for any help.

Oct 12, 2012 at 1:07 PM

I wonder if RegionManager.DeactivateView is something Jeremy meant to come back to but hasn't got round to, and is thus unfinished.  The reason I suspect that is the summary which says, "Activate a view, anywhere".  Also, it doesn't actually do anything, as written, except throw an exception if the viewName is not valid (unless, presumably, you override DeactivateControl in the RegionAdapter).  This is not a complaint, as I have found Jounce incredibly helpful.  Just speculating.

Oct 16, 2012 at 9:34 AM
Edited Oct 16, 2012 at 3:10 PM

In case anybody's following this thread, here's what I've done:

I downloaded the Jounce source code and included the Jounce.Silverlight5 project in my solution.  I modified RegionManager.ExportViewToRegion thus:


public void ExportViewToRegion(string viewName, string regionTag)
    if (_fluentViews.ContainsKey(viewName))

    _fluentViews.Add(viewName, regionTag);


This now does what I want, but I'm not happy that I've modified the source code, rather than just referencing the dll.  Somebody must have a better idea.  Anyone?