views:

32

answers:

0

Hello,

Do you see a better way how I can call/contstruct a Dialog from a Controller/ViewModel return data from it and set the DocumentViewModel as DataContext of the Dialog?

The problem is I can not use View first approach in the DocumentDetailWindow and its belonging UserControl because I can not set the Model to the DocumentViewModel`s Document Property in XAML!

How would you solve that scenario? Make Dialog properly bindable, call dialog and return data from it to the LessonPlannerController so the new Document can be saved on database and added to the bound ObservableCollection of Documents so the GUI is refreshed with one more Document.

LessonPlannerController/ViewModel:

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();
 }

UPDATE:

I have even thought about not making this => documentViewModel.Document = new Document(); because why do I need a Model in a in a ViewModel when I can just do this:

IN REALITY those properties have a NotifyPropertyChange... public string DocumentName {get;set;} public string Keywords {get;set;}

then I could create a Document instance with the above properties in the DocumentViewModel, when the Save command is executed and then pass the Document via Callback to the LessonPlannerControl etc... it seems View first is not working when you have to subscribe your event to a method. Only ViewModel first works then.

What do you think? Should I not use ocumentViewModel.Document = new Document();

and create those 2 properties in the DocumentViewModel. Hm... but why recreate if they are already in the Document Model?...