❔ Setting tab name dynamically

I am trying to set the header for a tab in a tabcontroll based on the content, but struggle to make it work.

I have the following wpf layout:
<TabControl  Grid.Row="1" Grid.Column="2"  
         ItemsSource="{Binding CurrentEditorsList, UpdateSourceTrigger=PropertyChanged}"
         SelectedIndex = "{Binding SelectedEditorIndex, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
         Name="EditorsTabControl">
    <TabControl.ItemTemplate>
        <DataTemplate>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                
                <TextBlock Grid.Column="0" Text="{Binding DisplayName.Value, UpdateSourceTrigger=PropertyChanged}">
                </TextBlock>
                <Button Grid.Column="1" 
                        Command="{Binding DataContext.CloseToolCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=TabControl}}" 
                        CommandParameter="{Binding}"
                        HorizontalContentAlignment="Right">
                </Button>
            </Grid>
        </DataTemplate>
    </TabControl.ItemTemplate>
</TabControl>


CurrentEditorsList is a UserControl where the DataContext is set to an object which has an object DisplayName.Value.
I have also tried DataContext.DisplayName.Value, but it also does not work.
How do I reference the content of the user control in this context?
Was this page helpful?