在区域中加载模块默认视图以创建菜单 [英] Load Module Default Views In Region to Create Menu

查看:195
本文介绍了在区域中加载模块默认视图以创建菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个M-V-VM应用程序,并在运行时动态加载模块.

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" />

看起来像

Module1View Module2View Module3View Module4View等

Module1View Module2View Module3View Module4View etc

先谢谢您.

推荐答案

我设法通过创建StackPanelRegion适配器并使用以下XAML做到了这一点

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

这篇关于在区域中加载模块默认视图以创建菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆