Dynamically create view models

Topics: Conventions, Framework Services
Oct 4, 2013 at 4:09 PM
Does anyone know how I could create view models dynamically?

I have a form in which the user can enter data, and each time that data is submitted, a meta data object is created and added to a list of meta data objects. When the user requests to see the data that has been entered, I want to be able to display all of the entered data on the screen. I've created a view / viewModel combination that displays data from a meta data object. I will have a list of an unknown length of these meta data objects (depending on how many times the user used the form to input data). From this list, I would like to create a viewModel and view dynamically for each object in the list, and then add the views/viewModels into my screen.

Is there a way I can do this using Caliburn Micro?
Oct 9, 2013 at 6:32 PM
jegan145 wrote:
Does anyone know how I could create view models dynamically?

I have a form in which the user can enter data, and each time that data is submitted, a meta data object is created and added to a list of meta data objects. When the user requests to see the data that has been entered, I want to be able to display all of the entered data on the screen. I've created a view / viewModel combination that displays data from a meta data object. I will have a list of an unknown length of these meta data objects (depending on how many times the user used the form to input data). From this list, I would like to create a viewModel and view dynamically for each object in the list, and then add the views/viewModels into my screen.

Is there a way I can do this using Caliburn Micro?
If you know the type of the view, you can call ViewModelLocator.LocateForViewType(). This will resolve the type name of the viewmodel and get an instance through the IoC container.
Marked as answer by jegan145 on 10/21/2013 at 9:19 AM