RegisterViewWithRegion - index out of range exception

Topics: Prism v4 - WPF 4
Sep 11, 2010 at 2:41 AM

Using: Prism Prism v4 - Drop 7, RibbonControlsLibrary 3.5.40729.1

I have a RibbonContextualTabGroupItemsControl that is a region. My ribbon binds to this for its ContextualTabGroupsSource property. This is so modules can register their own contexts for ribbon tabs they may inject.

 When I call RegisterViewWithRegion with 1 context, everything works fine. When I attempt to register another context Microsoft.Practices.Prism.Regions. ViewsCollection. OnCollectionChanged() throws an index out of range exception. As an experiment I wrapped the call in a try catch block and the ribbon does get both context objects, but neither will actually display.

 As a temporary work around I am binding the ItemsSource of the RibbonContextualTabGroupItemsControl to a collection in my shell's view model and it works but I have to reference my modules in the shell so this is not good.

Note that I do not have a region adapter for the ribbon, I just have those particular views inheriting from the objects the ribbon controls expect, which works fine for the ribbon tabs, just not for more than 1 RibbonTabContextualTabGroup.

Thanks

Sep 11, 2010 at 4:33 PM
Edited Sep 11, 2010 at 5:14 PM

disregard didn't catch the last note.

 

Morgan.

Sep 22, 2010 at 8:56 PM

Hi,

Base on my understanding in your scenario you have RibbonContextualTabGroupItemsControl, which derives from ItemsControl, so it acts as the main region of your application. The problem if you register more than one view to the region is that you get an error.

As you mentioned, you should not reference your modules from your shell. I’m not aware how RibbonControlsLibrary works, but did you try using View Injection instead? How to: Show a View in a Region Using View Injection UI Composition

I’m not sure if that can solve your problem, but it might give us some idea to clarify the scenario.

A repro sample would help too; do you have one at hand?

Fernando Antivero
http://blogs.southworks.net/fantivero