views:

135

answers:

2

I am builng an M-V-VM application with Dynamic Loading of modules at runtime.

Each of these Modules has a default view which individulally they show on the selected region when I go

_regionManager.Regions["BottomMenuRegion"].Add(
    Container.Resolve<AdminModuleView>(), "AdminView", true);

However, When the Next Module loads it overwrtites the previous loaded view.. How can I load more than one view into a region so that it creates a "Menu" displaying the default view? e.g

<ItemsControl cal:RegionManger.RegionName="BottomMenuRegion" />

looks like

Module1View Module2View Module3View Module4View etc

Thanking you in advance.

A: 

If I'm understanding you right you're trying to load into a region, but when you load objects into that region they are overwriting each other?

You can't load more then one view into one region. If you'd like to show a menu that will show other views, you'll have to make two regions and make your own menu. Put the menu showing code into the ModuleInit and then add some code to the click events of the menu items that will load up other views into a different "MainRegion"

thepaulpage
+1  A: 

I managed to do this by creating a StackPanelRegion Adapter and Using the following XAML

 <StackPanel  Orientation="Horizontal"
            cal:RegionManager.RegionName="BottomMenuRegion" >

            <ItemsControl>
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Grid/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>
        </StackPanel >

Region Adapter Code Here for those in the same situation

 public class StackPanelRegionAdapter : RegionAdapterBase<StackPanel>
    {
        public StackPanelRegionAdapter(IRegionBehaviorFactory behaviorFactory) :
            base(behaviorFactory)
        {
        }
        protected override void Adapt(Microsoft.Practices.Composite.Regions.IRegion region, StackPanel regionTarget)
        {
            region.Views.CollectionChanged += (s, e) =>
            {
                if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
                    foreach (FrameworkElement element in e.NewItems)
                        regionTarget.Children.Add(element);
                //Handle remove event as well.. 
            };
        }

        protected override Microsoft.Practices.Composite.Regions.IRegion CreateRegion()
        {
            return new AllActiveRegion();
        }
    }
Traci