我尝试从参数作为模型的基础架构解决方案进行导航,并设置DataContext
。
问题尽管我设置了不同的datacontext,但始终设置了第一个加载的数据文本。
UserControl _containerLoanView;
NavigationParameters navParameter = new NavigationParameters();
LoanModel loanModel = new LoanModel();
switch (loanType)
{
case "Weekly Loan":
_containerLoanView = _container.Resolve(typeof(object), Constants.LoanView) as UserControl;
_containerLoanView.DataContext = new WeekLoanVeiwModel();
navParameter.Add("WeeklyLoanVM", loanModel);
if (_regionManager.Regions[RegionNames.ManagementRegion].GetView(Constants.WeeklyLoanView) == null)
{
_regionManager.Regions[RegionNames.ManagementRegion].Add(_containerLoanView, Constants.WeeklyLoanView);
}
break;
case "Daily Loan":
_containerLoanView = _container.Resolve(typeof(object), Constants.LoanView) as UserControl;
_containerLoanView.DataContext = new DailyLoanViewModel();
navParameter.Add("DailyLoanVM", loanModel);
if (_regionManager.Regions[RegionNames.ManagementRegion].GetView(Constants.DailyLoanView) == null)
{
_regionManager.Regions[RegionNames.ManagementRegion].Add(_containerLoanView, Constants.DailyLoanView);
}
break;
}
_regionManager.RequestNavigate(RegionNames.ManagementRegion, new Uri(Constants.LoanViewLocation, UriKind.Relative), navParameter);