我使用的是Prism Unity,我有一个抽象的RecordViewModel:BindableBase,RecordListViewModel:RecordViewModel和RecordUpdateViewModel:RecordViewModel,INavigationAware。还有一个单独的导航模块,我的MainWindow有2个区域,NavigationRegion和ContentRegion。所有RecordViews都位于ContentRegion中。无论出于何种原因,无论我单击“返回”按钮还是单击NavigationRegion中的按钮,我都无法离开“更新”视图。我已经缩小了问题所在的是ViewModel,而我缺少了一些InavigationAware的东西。请告诉我我缺少或做错了什么,谢谢。public class RecordUpdateViewModel : RecordViewModel, INavigationAware{ private IRegionNavigationJournal navigationJournal; public RecordUpdateViewModel(IRecordService context) : base(context) { } public bool IsNavigationTarget(NavigationContext navigationContext) { return false; } public void OnNavigatedFrom(NavigationContext navigationContext) { throw new NotImplementedException(); } public void OnNavigatedTo(NavigationContext navigationContext) { //irrelevant to problem logic to bring in Record.Id navigationJournal = navigationContext.NavigationService.Journal; }}
2 回答
汪汪一只猫
TA贡献1898条经验 获得超8个赞
INavigationAware与在视图之间导航无关。它只是为您提供了一种在视图之间传递参数的简便方法。我认为您正在寻找的是名为IRegionManager的东西,那么您可以做一些事情,就像regionManager.NavigateTo(regionName,viewName)
您必须在容器中注册视图一样。类似的东西container.RegisterType<object,Views.View>(ViewNames.ViewName);
当然ViewNames.ViewName
是带有视图名称的常量字符串。
慕婉清6462132
TA贡献1804条经验 获得超2个赞
我将羞愧地垂头丧气...看一下OnNavigatedFrom ...以及所有其他3个INavigationAware成员,以寻找其他人...并删除自动生成的NotImplementedException。如果您不需要该空白,那么它必须在那里,这样INavigationAware不会因为没有完全实现它而大喊大叫,但是如果您不需要它们,那么这些空白中就不必有任何逻辑。
- 2 回答
- 0 关注
- 185 浏览
添加回答
举报
0/150
提交
取消