【发布时间】:2017-06-29 06:13:07
【问题描述】:
我正在努力在 WPF PRISM 应用程序的两个视图之间传递导航参数。
我的应用程序的基本结构如下: 我有一个 viewmodels 文件夹,里面我的应用程序的每个“部分”都有一个文件夹,只是为了帮助逻辑地构建事物,即。订单、项目
这同样适用于视图。
我正在从订单文件夹中的视图导航到项目文件夹中的视图。
实际导航工作正常,应用程序在我的第二个视图模型的构造函数中遇到断点,但从未调用 INavigationAware 接口方法。
我不确定这是否与由于文件夹而存在于不同命名空间中的视图/视图模型有关?
这里是我使用的重要代码sn-ps:
引导程序
Container.RegisterType(typeof(Object), typeof(ConfirmOrders), "Orders.ConfirmOrders");
Container.RegisterType(typeof(Object), typeof(QuotedCosts), "Projects.QuotedCosts");
从 ConfirmOrders 导航到 QuotedCosts
NavigationParameters par = new NavigationParameters();
par.Add("ProjectID", ProjID);
_regionManager.RequestNavigate("ContentRegion", "Projects.QuotedCosts", par);
永远不会调用导航事件的 QuotedCosts 视图模型
public class QuotedCostsViewModel : ViewModelBase, INavigationAware
{
private IProjectService _projectService;
private int ProjectID { get; set; }
public mProject CurrProject { get; protected set; }
public QuotedCostsViewModel(IProjectService projectService)
{
_projectService = projectService;
CurrProject = _projectService.GetProjectDetails(ProjectID);
}
public void OnNavigatedTo(NavigationContext navigationContext)
{
ProjectID = int.Parse(navigationContext.Parameters["ProjectID"].ToString());
}
public bool IsNavigationTarget(NavigationContext navigationContext)
{
return true;
}
public void OnNavigatedFrom(NavigationContext navigationContext)
{
}
}
【问题讨论】:
-
能否请您从发送参数的位置发布代码,即您正在使用的 Uri Query..
-
它在第二个代码块中,我没有使用 Uri 查询,而是使用导航参数重载
-
代码看起来没问题@ThatChris 需要通过替换命名空间来识别..否则它是一个热门和试用问题
-
感谢您的检查,我刚刚弄明白了。 . .没有意识到 OnNavigatedTo 事件是在构造函数之后调用的。如果你仔细想想,这完全合乎逻辑。