Loading default values ​​in a module to create a menu

I am creating an MV-VM application with dynamic loading of modules at runtime.

Each of these modules has a default view, which individually they show in the selected area when I go

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

However, when the next module loads, it overwrites the previous loaded view. How to load more than one view into an area to create a β€œMenu” displaying the default view? eg

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

looks like

Module1View Module2View Module3View Module4View, etc.

Thank you in advance.

+1
source share
2 answers

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(); } } 
+1
source

If I understand you correctly, you are trying to upload to a region, but when you upload objects to this region, do they overwrite each other?

You cannot load more than one view in one region. If you want to show a menu in which other views will be displayed, you will need to make two regions and create your own menu. Put the menu that displays the code in ModuleInit, and then add some code to the click events of the menu items that will load other views into another "MainRegion"

0
source

All Articles