Hosting a bound control within another bound control.

Aug 25, 2010 at 10:01 PM

Sacha, could you please illustrate or send an example of how to host a user control bound to a view model inside another user control bound to another view model? One method of doing this would be to bind a content control or something similar in the parent container to a new workspace defined within the parent view model. How can this be done? Another method would be to host the user control within the parent, but I can't pass the dataValue from the parent view model to the child control's view model. Any help will be appreciated. 


Aug 26, 2010 at 7:51 AM

This is pretty much what the WPF demo app does, have a look at the MainWindow and how is created workspaces that is essentially what you are asking for. MainWindowViewModel creates workspaces and passes them data, and then these are used to create Views using a DataTemplate. This is exactly what you are asking for.


You can just use a ItemsControl, which one has one item, and follow the TabControl example from the WPF demo. That IS what you are asking for.

Aug 26, 2010 at 11:57 AM

Sacha, thank you for your fast reply, I understand what you said, however I need a way to bind the ItemsControl directly to the workspacedata itself and not the Views property contained in the base class. Reason for this is my parent control could contain multiple child controls in which case I need to create a workspace for each individual child control (in this case multiple ItemsControls) inside the parent container, and bind to it. 

Aug 26, 2010 at 12:38 PM

I still think what I am proposing would work for you. Truth is I would have to do same experiments as you, and right now I just have no time. I tried to make articles as good as I could, but I do get loads of people looking for me to solve everything for them (not saying you are one of those, you seem to know whats what), but as a result I can not answer every question giving full source code, I am just far too busy. Sorry to say, but on this occasion you may need to try a few things out.