Load Module Default Views In Region to Create Menu

走远了吗. 提交于 2019-12-23 03:17:27

问题


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.


回答1:


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



回答2:


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"



来源:https://stackoverflow.com/questions/2325809/load-module-default-views-in-region-to-create-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!