我有三个区域:
<Grid>
<DockPanel LastChildFill="True">
<ContentControl DockPanel.Dock="Top" prism:RegionManager.RegionName="{x:Static inf:
RegionNames.TheUpperRegion}" Margin="5" />
<ContentControl prism:RegionManager.RegionName="{x:Static inf:
RegionNames.TheBottomRegion}" Margin="5"/>
</DockPanel>
<ContentControl prism:RegionManager.RegionName="{x:Static inf:RegionNames.TheWholeRegion}"
Margin="5" />
</Grid>
此代码正确地从TheWholeRegion
导航到TheBottomRegion
区域:
Uri viewUpper = new Uri("ModuleItems", UriKind.Relative);
Uri viewBottom = new Uri("ModuleItems", UriKind.Relative);
regionManager.RequestNavigate(RegionNames.TheBottomRegion, viewBottom);
var loginView = regionManager.Regions[RegionNames.TheWholeRegion].Views.ElementAt(0);
regionManager.Regions[RegionNames.TheWholeRegion].Remove(loginView);
然而,如果我尝试同时加载两个区域,那么我会看到"System.Object"而不是Views:
Uri viewUpper = new Uri("ModuleItems", UriKind.Relative);
Uri viewBottom = new Uri("ModuleItems", UriKind.Relative);
regionManager.RequestNavigate(RegionNames.TheUpperRegion, viewUpper);
regionManager.RequestNavigate(RegionNames.TheBottomRegion, viewBottom);
var loginView = regionManager.Regions[RegionNames.TheWholeRegion].Views.ElementAt(0);
regionManager.Regions[RegionNames.TheWholeRegion].Remove(loginView);
我做错了什么?
我需要的是在Unity
容器中注册System.Object
和视图类型之间的类型映射:
protected override void RegisterTypes()
{
Container.RegisterType<object, TheBottomControl>("ModuleItemsBottom");
Container.RegisterType<IBottomViewModel, TheBottomControlViewModel>();
Container.RegisterTypeForNavigation<TheBottomControl>();
Container.RegisterType<object, TheUpperControl>("ModuleItemsUpper");
Container.RegisterType<IUpperViewModel, TheUpperControlViewModel>();
Container.RegisterTypeForNavigation<TheUpperControl>();
}
和要请求的代码:
Uri viewUpper = new Uri("ModuleItemsUpper", UriKind.Relative);
Uri viewBottom = new Uri("ModuleItemsBottom", UriKind.Relative);
regionManager.RequestNavigate(RegionNames.TheUpperRegion, viewUpper);
regionManager.RequestNavigate(RegionNames.TheBottomRegion, viewBottom);
var loginView = regionManager.Regions[RegionNames.TheWholeRegion].Views.ElementAt(0);
regionManager.Regions[RegionNames.TheWholeRegion].Remove(loginView);