❔ 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>
<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?
1 Reply
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server