Wpf 准备好对话框ViewModel绑定,调用对话框并在MVVM中从中返回数据
您认为有更好的方法可以从控制器调用/contstruct对话框/ViewModel从中返回数据并将DocumentViewModel设置为对话框的DataContext吗 问题是我无法在DocumentDetailWindow及其所属的UserControl中使用视图优先方法,因为我无法在XAML中将模型设置为DocumentViewModel的文档属性 你将如何解决这种情况?使Dialog可正确绑定,调用Dialog并将数据从它返回到LessonPlannerController,这样新文档就可以保存在数据库中,并添加到绑定的ObservableCollection文档中,这样GUI就会用一个以上的文档刷新 LessonPlannerController/ViewModel:Wpf 准备好对话框ViewModel绑定,调用对话框并在MVVM中从中返回数据,wpf,callback,dialog,viewmodel,datacontext,Wpf,Callback,Dialog,Viewmodel,Datacontext,您认为有更好的方法可以从控制器调用/contstruct对话框/ViewModel从中返回数据并将DocumentViewModel设置为对话框的DataContext吗 问题是我无法在DocumentDetailWindow及其所属的UserControl中使用视图优先方法,因为我无法在XAML中将模型设置为DocumentViewModel的文档属性 你将如何解决这种情况?使Dialog可正确绑定,调用Dialog并将数据从它返回到LessonPlannerController,这样新文档就
private void OnAddDocument()
{
DocumentDetailWindowaddDocumentWindow = new DocumentDetailWindow();
DocumentViewModeldocumentViewModel = new DocumentViewModel();
documentViewModel.Document = new Document();
documentViewModel.Repository = new LessonPlannerRepository();
documentViewModel.SaveDocumentDelegate += new Action<Document>(OnSaveDocument);
addDocumentWindow.DataContext = documentViewModel;
addDocumentWindow.ShowDialog();
}
专用void OnAddDocument()
{
DocumentDetailWindowaddDocumentWindow=新建DocumentDetailWindow();
DocumentViewModeldocumentViewModel=新的DocumentViewModel();
documentViewModel.Document=新文档();
documentViewModel.Repository=新建LessonPlannerRepository();
documentViewModel.SaveDocumentDelegate+=新操作(OnSaveDocument);
addDocumentWindow.DataContext=documentViewModel;
addDocumentWindow.ShowDialog();
}
更新:
我甚至想过不做这个=>documentViewModel.Document=new Document();
因为当我可以这样做时,为什么我需要ViewModel中的模型:
实际上这些属性具有NotifyPropertyChange。。。
公共字符串DocumentName{get;set;}
公共字符串关键字{get;set;}
然后,当执行Save命令时,我可以在DocumentViewModel中创建具有上述属性的文档实例,然后通过回调将文档传递给LessonPlannerControl等。。。当您必须将事件订阅到某个方法时,View first似乎不起作用。只有ViewModel首先起作用
你觉得怎么样?我不应该使用ocumentViewModel.Document=newdocument()
并在DocumentViewModel中创建这两个属性。陛下但是,如果它们已经在文档模型中,为什么要重新创建呢?…这些是否回答了您的问题? 或
+1用于与自己的迷你对话:)