Prism 6:RequestNavigate() 仅适用于一个区域
Prism 6: RequestNavigate() working for just one region
我有三个区域:
<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" 而不是视图:
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);
我有三个区域:
<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" 而不是视图:
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);