Perserve order with ItemsControl and TabControl regions

Topics: Prism v2 - WPF 3.5
Mar 13, 2009 at 6:55 PM
Is it possible to specify a order when injecting views into a ItemsControl region or TabControl region? I don't see a way out of the box in Prism to do this, so what's the best approach to achieve this. I know that the views themselves shouldn't have to be aware of the order in the host control. But it'd still be nice to have some predictability.
Mar 16, 2009 at 5:08 PM

Unfortunately, this is not easily possible with the current version of prism.

Apr 7, 2009 at 7:49 PM



It took some time but with Matias Bonaventura and Ezequiel Jadib we were able to create an extension method for the RegionManager to add a view to a region at a particular index, using an extension method for the RegionManager. Although I do not know what your specific use case is, I believe you might find it useful:

·         How to Add a View to a Region in a particular index with Prism-v2


Remember that this probably isn’t the best way to get this to work, but it is a suitable approach.


Please let me know if this helps.


Damian Schenkelman

Aug 9, 2009 at 3:38 PM
Edited Aug 9, 2009 at 3:41 PM

I was looking for something similar: my priority is that a particular view is always first and that it is active.  I like the way you took the approach of only fiddling with the order and leaving the active view active but in my case I wanted the first view always to be active, so I replaced your ActiveView code bits with:

if (mainRegion.Views.Count() > 0)

I'm still getting to grips with CAG so this may not be correct but it works and that will do for now.

Thank you very much for your work on this.

Aug 21, 2009 at 11:03 AM

Hi All,


I tried to implement this solution but this is not working if it's applied to a view discovery approach. Is there any adaptation to make it work even if a needed region is not yet created ?


Thanks in advance

Aug 24, 2009 at 7:57 AM
Edited Aug 24, 2009 at 7:59 AM

Hi again,

I found this post : but i'm not sure how to implement his solution as there's no details




Aug 24, 2009 at 9:14 AM

The problem in the solution of Damian, Matias & Ezequiel is linked to this very first line of the RegisterViewWithRegionInIndex method :


public static IRegionManager RegisterViewWithRegionInIndex(this IRegionManager regionManager, string regionName, Func<object> getContentDelegate, int index)
            IRegion mainRegion = regionManager.Regions[regionName];</object>


The region name in which i want to register my views is a scoped region, it is not created yet therefore i don't have it in the Region manager yet.

Any help ?