MVVM - New views from model

Dec 15, 2009 at 2:54 PM

 

Suppose I have a MainView with a Grid named LayoutRoot. This view can have N views created into it and the user create/remove the views... What is the best solution, according to MVVM pattern, to create and add the new views in the layout (eg: LayoutRoot.Children.Add(new View))?
My solution was: Create a static class named ContainerManagerService, each container view register, each vm need to know where it wants to add a new view, so from viewmodel I use: 
ContainerManagerService.GetContainer("containerName").Add(new MyNewChildView());
Is this a correct approach?

Suppose I have a MainView with a Grid named LayoutRoot. This view can have N views created into it and the user create/remove the views...

What is the best solution, according to MVVM pattern, to create and add the new views in the layout (eg: LayoutRoot.Children.Add(new View))?

My solution was: Create a static class named ContainerManagerService, each container view register, each vm need to know where it wants to add a new view, so from viewmodel I use: 

ContainerManagerService.GetContainer("containerName").Add(new MyNewChildView());

 

Is this a correct approach?