本文介绍了WPF数据绑定TabItem标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将数据对象的ObservableCollection绑定到我的选项卡控件项源.我已经正确地弄清楚了如何在生成的Tabitem中绑定控件,但是我无法弄清楚如何更改使用Observable Collection中的a属性生成的Tabitem的header属性.抱歉,我的措词不正确.这是我的Tabitem数据模板的XAML:

I am binding a ObservableCollection of data objects to my tab control item source. I have correctly figured out how to bind the controls within the tabitem that is generated, however I cannot figure out how to change the header property of the tabitem that is generated using the a property within the Observable Collection. Sorry if I am wording this incorrectly. Here is my XAML for the tabitem data template:

<DataTemplate x:Key="TabItemTemplate">
        <TreeView Height="461" VerticalAlignment="Top" 
            Width="625" ItemTemplateSelector="{StaticResource TreeviewDataSelector}" ItemsSource="{Binding}" />
</DataTemplate>

推荐答案

为您的TabItem创建样式,该样式会设置 Header 属性,并将样式应用于 TabControl.ItemContainerStyle

Create a Style for your TabItems that sets the Header property, and apply the style to TabControl.ItemContainerStyle

<TabControl>
    <TabControl.ItemContainerStyle>
        <Style TargetType="TabItem">
            <Setter Property="Header" Value="{Binding PathToYourProperty}"/>
        </Style>
    </TabControl.ItemContainerStyle>
</TabControl>

这篇关于WPF数据绑定TabItem标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 01:40