C# Prism 导航问题
我有两个区域。导航区域和主区域。
我的导航区域包含两个调用 RequestNavigate 方法的按钮。 第一个按钮加载不带任何参数的视图
this.tRegionManager.RequestNavigate(RegionNames.MainRegion, ViewNames.VInfoMainViewUri);
第二个按钮应加载带有一些参数的相同视图
this.tRegionManager.RequestNavigate(RegionNames.MainRegion, new Uri(ViewNames.VInfoMainViewUri.OriginalString + "" + query.ToString(), UriKind.Relative));
如果没有加载视图,则效果很好。如果加载了任何视图,则单击任何按钮都不会产生任何影响。
我尝试从我的区域中删除每个活动视图,但这会导致错误
IViewsCollection col = tRegionManager.Regions[args.RegionName].Views;
foreach (var obj in col)
{
tRegionManager.Regions[args.RegionName].Remove(obj);
}
该区域不包含指定的视图。 参数名称:视图
如何修复此问题?
I have two regions. A navigation region and a main region.
My navigation region contains two buttons which call the RequestNavigate method.
The first button loads a view without any parameters
this.tRegionManager.RequestNavigate(RegionNames.MainRegion, ViewNames.VInfoMainViewUri);
The second button should load the same view with some parameters
this.tRegionManager.RequestNavigate(RegionNames.MainRegion, new Uri(ViewNames.VInfoMainViewUri.OriginalString + "" + query.ToString(), UriKind.Relative));
This works fine if no view is loaded. If any view is loaded, a click on any button causes nothing.
I tried to remove every active view from my region, but this causes an error
IViewsCollection col = tRegionManager.Regions[args.RegionName].Views;
foreach (var obj in col)
{
tRegionManager.Regions[args.RegionName].Remove(obj);
}
The region does not contain the specified view.
Parameter name: view
How can I fix this probem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想要创建一个新视图,即使该区域中已经存在相同类型的视图,您也需要在您的 View 或 ViewModel 中实现 INavigationAware 接口(Prism 将首先检查视图,如果它没有实现
INavigationAware
它也会检查 ViewModel)。您对
IsNavigationTarget
方法特别感兴趣,该方法告诉 Prism 是否应重用当前视图实例,或者是否应创建另一个实例来满足导航请求。因此,要始终创建一个新视图,您可以这样做:所有这些都在 Prism 4 文档的第 8 章中进行了更详细的解释;他们还有其工作原理的说明。
If you want to create a new view even when there is already an existing view of the same type in the region, you need to implement the
INavigationAware
interface either in your View or your ViewModel (Prism will check first the view, and if it doesn't implementINavigationAware
it will also check the ViewModel).You are interested specifically in the
IsNavigationTarget
method, which tells Prism if the current instance of the View should be reused, or if another instance should be created to satisfy the navigation request. So, to always create a new View you would do:All of this is explained in greater detail in Chapter 8 of the Prism 4 documentation; they also have an illustration of how it works.