Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Databinding TabItem Headers

Tags:

c#

.net

wpf

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>
like image 541
secretformula Avatar asked Aug 23 '11 17:08

secretformula


2 Answers

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>
like image 103
Yuriy Zanichkovskyy Avatar answered Nov 03 '22 11:11

Yuriy Zanichkovskyy


Set the DisplayMemberPath on the TabControl to the name of the property.

<TabControl ItemsSource="{Binding items}" DisplayMemberPath="headerPropertyName">
like image 15
Ben Barefield Avatar answered Nov 03 '22 11:11

Ben Barefield