C# 如何在模块中使用prism导航多个视图
我是Prism的新手,所以需要一些视图导航方面的帮助 在我的项目中,我只有4个视图,所以我在一个模块中创建了所有视图。我已经创建了shell和引导程序。我需要做的是,我需要将一些数据从一个视图传递到另一个视图(例如,第一个视图有员工列表,我选择一个员工,我将单击按钮以获取该员工的详细信息)。目前我使用的是ViewModel优先方法`C# 如何在模块中使用prism导航多个视图,c#,wpf,navigation,prism,C#,Wpf,Navigation,Prism,我是Prism的新手,所以需要一些视图导航方面的帮助 在我的项目中,我只有4个视图,所以我在一个模块中创建了所有视图。我已经创建了shell和引导程序。我需要做的是,我需要将一些数据从一个视图传递到另一个视图(例如,第一个视图有员工列表,我选择一个员工,我将单击按钮以获取该员工的详细信息)。目前我使用的是ViewModel优先方法` _container.RegisterType<DashboardView>(); _container.RegisterType<Prepare
_container.RegisterType<DashboardView>();
_container.RegisterType<PrepareRunView>();
_container.RegisterType<IDashboardViewViewModel, DashboardViewViewModel>();
_container.RegisterType<IPrepareRunViewViewModel, PrepareRunViewViewModel>();
_regionManager.RegisterViewWithRegion(RegionNames.MainRegion, typeof(DashboardView));
_regionManager.RegisterViewWithRegion(RegionNames.MainRegion, typeof(PrepareRunView));
\u container.RegisterType();
_container.RegisterType();
_container.RegisterType();
_container.RegisterType();
_regionManager.RegisterViewWithRegion(RegionNames.MainRegion,typeof(DashboardView));
_regionManager.RegisterViewWithRegion(RegionNames.MainRegion,typeof(PrepareRunView));
提前感谢您可以使用事件聚合器进行通信
第一个视图(选择员工的视图)的视图模型需要引用Prism的IRegionManager对象。导航到第二个视图并按如下方式向其传递一些数据,非常类似于URL中的查询字符串值:-
var uriQuery = new UriQuery();
uriQuery.Add("empid", "123");
// Add more name/value pairs if you wish!
var viewName = "your_view_name" + uriQuery;
_regionManager.RequestNavigate("your region name", viewName);
如您所见,您可以通过指定视图名称导航到视图。为了实现这一点,您需要在IoC容器的名称下注册视图(如何注册取决于您使用的容器)
在要导航到的视图的视图模型中,实现INavigationAware界面:-
public bool IsNavigationTarget(NavigationContext navigationContext)
{
return true;
}
public void OnNavigatedFrom(NavigationContext navigationContext)
{
}
public void OnNavigatedTo(NavigationContext navigationContext)
{
// This will be called whenever the view is navigated to.
// Extract the querystring value(s).
var employeeId = navigationContext.Parameters["empid"];
.. etc..
}
如何在模块中激活和停用视图?谢谢,您如何在模块文件中激活和停用视图?这就像当我导航到不同的屏幕时,我需要激活新的屏幕。