What is best Practice in a wpf mvvm with multiple datacontext

simsenVejle

Well-known member
Joined
Feb 14, 2021
Messages
46
Programming Experience
Beginner
Hi,

I'm designing a wpf program with mvvm and now I'm confused which way I should do the "problem" with multiple datacontext to a usercontrol.

I have googled a lot and find out, that I can do it in two ways;

Make the vm extended with the foreign key and these properties in the view model

Or

Make a databinding to the second datacontext.

My overview:
I have a usercontrol where I bind to the DataContext CategoryViewModel in codebehind.

But in the Category model there is an foreign key to the Project model.

In the Usercontrol I want a combobox with all the projects and then the selected project should be the selected Categorys ProjectId

Now I do not know what is best practice databind to multiple datacontexts or to do it in the ViewModel?

Best regards
Simsen :)
 
Solution
In the ViewModel. That is its job. It acts as a Facade in front of the Model so that the View doesn't have to know the details of the Model implementation.
In the ViewModel. That is its job. It acts as a Facade in front of the Model so that the View doesn't have to know the details of the Model implementation.
 
Solution
Back
Top Bottom