WPF TabItem Binding Table Headers

I bind the ObservableCollection of data objects to the source tab control element. I correctly understood how to link the controls inside the created tabitem, however I cannot figure out how to change the tabitem header property that is created using the a property in the Observable Collection. Sorry if I put it wrong. 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> 
+6
source share
2 answers

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

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

Set DisplayMemberPath to TabControl on the property name.

 <TabControl ItemsSource="{Binding items}" DisplayMemberPath="headerPropertyName"> 
+10
source

Source: https://habr.com/ru/post/895694/


All Articles