Closed jinyuttt closed 9 months ago
Traditionally, these aspects are expected to be implemented by the developer and not the framework as there are too many opinions on implementation.
TabItem.Header
supports arbitrary content. So you can use a StackPanel, TextBlock, and Button for the closing part. If you're generating TabItem
s through a collection binding (ItemsSource
), then you create DataTemplate
s for the header and content. Something like:
<TabControl ItemsSource="{Binding Items}">
<TabControl.ItemTemplate>
<DataTemplate x:DataType="vm:SomeViewModel">
<StackPanel Orientation="Horizontal">
<TextBlock MinWidth="50" Text="{Binding Description}" />
<Button Command="{Binding Close}" />
</StackPanel>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate x:DataType="vm:SomeViewModel">
<ContentControl Content="{Binding}" />
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
Since data can be put into the TabControl
in multiple ways, it's up to you to implement the removal. If you're binding the ItemsSource
to an ObservableCollection<T>
, you simply remove the item from the collection.
AFAIK, there's no built-in support for an inline button to add items. That might require re-templating or clever use of TabItem.Header
.
Can style be used to implement it?