This project is read-only.

Different views on TabControl

Aug 23, 2011 at 9:50 AM

I'm trying to write a program that uses tabs to hold different usercontrols. What I currently want to happen is the user clicks a find button, a new tab is created, and a find screen appears inside it. Using the find screen the user can select clients and these then open in their own new tabs allowing the user to edit them. So if the user went in and selected three clients, the screen would have four tabs, one for the find screen and three client tabs.

My problem is that I'm not sure how to set this up in my program. I've created a TabControl and bound the ItemsSource to a collection of viewmodels (that I can add to whenever a user adds a new screen). I can use a DataTemplateSelector to select the DataTemplate that contains the right view, but I don't know how to set the resource of the view to my viewmodel.

I'm doing this in WPF and I'm using Bxf to do this, and this normally works but I'm unsure how it fits in with the TabControl.

Has anyone done something similar to this before (preferably using Bxf)?

Aug 23, 2011 at 4:55 PM

this post may be of interest

Aug 26, 2011 at 12:51 PM

I've just answered my own question.

The tabitems that get created dynamically are set up with a datacontext of the individual item from the tabcontrols itemsource property, in this case one of my viewmodels.

The datatemplate I used correctly picks up the correct view for the viewmodel type and displays this.

However my view set the datacontext of the grid on the view to my resource and so nothing was showing up. I've changed this to use the datacontext instead of the resource and now everything is working.

My only concern is that I was using the resource as that's how Rocky has his views set up. I just feel that I may as well change all my views to use datacontext and delete the resources that use to hold my model.

Has anyone else felt they have had to do this?