本文介绍了我如何能?将一个类中的TabItem绑定到另一个类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C#,WPF和XAML的初学者.

如何将WPF类绑定到另一个WPF类中的TabItem?

我想做的是创建一个具有多个选项卡的WPF窗口,然后为了易于使用&维护以创建单独的类,每个类包含每个TabItem下的内容的所有显示和处理详细信息.

下面是一个TabItem.可以说我有一个名为ClientAddressItems的类.

如何将其及其所有内容绑定到下面的TabItem?显然,TabItem有很多代码,包括位于其上方的TabControl和位于其下方的许多其他TabItem.

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.

<!-- Address Details Tab -->
            <TabItem Name="Item_Addresses"

                     Header="Addresses"

                     Grid.ColumnSpan="7"

                     Style="{StaticResource tabItemLevel3}"

                     BorderBrush="#FFCCCCCC">
             </TabItem>


只是为了澄清我正在尝试做的事情的深度.请注意:

在实际应用中:

1.主屏幕上将有许多TabItem,其中每个都有TabItem.
2.即TAB1 ====================================================================================================================================================================================================================================================================================================........ Tab1A,Tab1B,Tab1C等,每个选项卡
3.现在Tab1A将绑定到单独的类.
4.此单独的类肯定会具有一个地址列表.但在此之下还会有许多TabItem,并且每个TabItem都需要绑定到另一个单独的类.

总之,我想使用地址是一个不好的例子.

选项卡树如下所示:仅未列出选项卡名称.

Lvl1标签-维护标签,贸易标签等
Lvl2标签-客户维护标签,客户维护,国家维护等-在维护标签下
Lvl3选项卡-``客户地址''选项卡,``客户联系人'',``客户分支机构'',``客户...''等-在``客户维护''下
Lvl4标签等等

如您所见,这可能会变得很大.


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.

推荐答案

<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.



这篇关于我如何能?将一个类中的TabItem绑定到另一个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 13:40