我在 SilverLight 4 应用程序中使用 PRISM。我有一个问题,注册到某些区域的视图没有显示。
在启动时加载模块时,我将一些视图注册到区域,如下所示:
RegionManager.RegisterViewWithRegion("MyRegion1", typeof(IMySubView1));
RegionManager.RegisterViewWithRegion("MyRegion2", typeof(IMySubView2));
我有一个视图实现了一个名为 IMyView 的接口,其中 xaml 有两个内容控件,其区域在网格中定义,如下所示:
<ContentControl Regions:RegionManager.RegionName="MyRegion1" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Grid.Row="0" Grid.RowSpan="1"/>
<ContentControl Regions:RegionManager.RegionName="MyRegion2" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Grid.Row="1" Grid.RowSpan="1"/>
我尝试了两种不同的方法来将视图添加到主要区域。两者都添加了视图和显示按钮等基本元素,但视图中定义的区域不会被关联的视图填充。
方法一:
object obj = _container.Resolve<IMyView>();
IRegion mainRegion = _regionManager.Regions["MainViewRegion"];
IRegionManager scoped = mainRegion.Add(obj, "test", true);
mainRegion.Activate(obj);
// Enabling the following call, it will fail saying the region MyRegion1 does not exist. Feels like it should?
// IRegion myRegion = scoped.Regions["MyRegion1"];
方法二:
object obj = _container.Resolve<IMyView>();
_regionManager.AddToRegion("MainViewRegion", obj);
_regionManager.Regions["MainViewRegion"].Activate(obj);
感觉就像在 xaml 文件中定义的区域没有被注册,因此注册的视图没有被显示。
MainViewRegion 在 shell 中的 TabControl 中定义如下:
<TabControl Margin="8,0,8,8" Regions:RegionManager.RegionName="MainViewRegion">
任何有关解决我的问题的建议将不胜感激!