Click here to Skip to main content
16,004,727 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am a Beginner at C#, WPF and XAML.

How do I bind a WPF Class to a TabItem in another WPF Class?

What I am trying to do is create a WPF Window with multiple Tabs and then for ease of use & maintenance to create separate classes each containing all the display and processing details for what goes under the each TabItem.

Below is a TabItem. Lets say I have a class called ClientAddressItems.

How would I bind it and all its contents to the below TabItem? Clearly, The TabItem has a lot of code including a TabControl above it and also has many other TabItems below it.
HTML
<!-- Address Details Tab -->
            <TabItem Name="Item_Addresses"
                     Header="Addresses"
                     Grid.ColumnSpan="7"
                     Style="{StaticResource tabItemLevel3}"
                     BorderBrush="#FFCCCCCC">
             </TabItem>

Just to clarify the deapth of what I am trying to do. Please note:

In the actual application:

1. The main screen will have many TabItems with TabItems within each.
2.i.e, TAB1================TAB2=============TAB3
........Tab1A,Tab1B,Tab1C, etc for each Tab
3. Now Tab1A is would bind to a seperate Class.
4. This seperate Class will definately have an Address List. But will also have a number of TabItems under that and each one of those TabItems would need to bind to another seperate Class.

In summary I guess using adresses is a bad example.

The tree of tabs would be something like this: Only not the Tab names listed.

Lvl1 tabs - Maintenance Tab, Trade Tab, etc
Lvl2 tabs - Client Maint Tab, Customer Maint, Country Maint, etc - under the Maint Tab
Lvl3 tabs - Client Addresses Tab, Client Contacts, Client Branches, Client ...., etc - under Client Maint
Lvl4 tabs, etc

As you can see this can become ver large.
Posted
Updated 15-Mar-12 14:51pm
v3
Comments
[no name] 15-Mar-12 19:03pm    
Other than needing to have a better design (tabs inside of tabs inside of tabs) Wayne's answer gave you what you needed so what is the problem?

I don't think you are quite getting it. If you had a class ClientAddressItems which contained the client address, and which you wanted to display on that particular tab, you would bind the DataContext of the TabItem to the address class, and then bind individual items to controls within the TabItem

HTML
<tabitem name="Item_Addresses">
                     Header="Addresses"
                     Grid.ColumnSpan="7"
                     Style="{StaticResource tabItemLevel3}"
                     BorderBrush="#FFCCCCCC"
                     DataContext="{Binding Path=AddressCollection}">
               <label content="Street" />
               <textbox text="{Binding Path=Street}" />
             </tabitem>

I am assuming that the address collection holds the address for your selected client.
 
Share this answer
 
Comments
MyPortMan 15-Mar-12 9:29am    
Wayne I hear what you say. However, The real class that needs to bind to the TabItems has a lot more than just addresses in it. It has address information and a whole screen of information including TabItems of its own that will need to bind to other classes and modules.
If you take a look here:
http://tap-source.com/mvvm-tabcontrol/[^]

That show's you how to separate your logic from your view using MVVM.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900