1 回答
TA贡献1833条经验 获得超4个赞
您的 StudentsReport.xaml UserControl 绑定到在 XAML 中创建的 StudentsReportViewModel 实例:
<UserControl.DataContext>
<vm:StudentsReportViewModel/>
</UserControl.DataContext>
然而,“生成报告”按钮正在调用在 MainWindowVieModel 构造函数中创建并存储在 Report 类中的 StudentsReportViewModel 的另一个实例。
Reports = new List<Report>
{
new Report{ Name = "Students Report", ViewModel = new StudentsReportViewModel()},
new Report{ Name = "Marks Report", ViewModel = new MarksReportViewModel()}
};
您需要删除其中一个实例,以便将 UserControl 的 DataContext 绑定到您从中生成报告消息的同一视图模型实例。我建议从 StudentsReport.xaml 中删除这段代码:
<UserControl.DataContext>
<vm:StudentsReportViewModel/>
</UserControl.DataContext>
- 1 回答
- 0 关注
- 204 浏览
添加回答
举报
