You should use <TabControl x:Name="sheetMain" ContentTemplate="{DynamicResource TabCtnts}" ItemTemplate="{DynamicResource TabHdr}" />
in your DockPanel to layout the TabControl. I did some updates for your code and binded some data for it. Below is my code for you:
<Window.Resources>
<DataTemplate x:Key="TabCtnts">
<ListBox>
<ListBoxItem Content="{Binding ID}" />
<ListBoxItem Content="{Binding Name}" />
</ListBox>
</DataTemplate>
<DataTemplate x:Key="TabHdr">
<StackPanel Orientation="Horizontal" DataContext="{Binding DataContext, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TabItem}}}">
<Label VerticalAlignment="Center" VerticalContentAlignment="Center" MaxWidth="397">
<Label.Content>
<TextBlock TextTrimming="WordEllipsis" Text="{Binding Title}" ToolTip="{Binding Title}" />
</Label.Content>
</Label>
<Button ToolTip="Close this script" Background="{x:Null}">✘</Button>
</StackPanel>
</DataTemplate >
<DataTemplate x:Key="Tab">
<TabItem ContentTemplate="{DynamicResource TabCtnts}" HeaderTemplate="{DynamicResource TabHdr}" />
</DataTemplate>
</Window.Resources>
<DockPanel>
<Border DockPanel.Dock="Top" BorderBrush="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" BorderThickness="0,0,0,1" Margin="0,0,0,3" Padding="0,3,0,0">
<StackPanel x:Name="toolBar" Orientation="Horizontal">
<Button x:Name="btnOpen" Content="Open" />
<Separator />
<Button x:Name="btnFullScreen" Content="Full Screen"/>
</StackPanel>
</Border>
<TabControl x:Name="sheetMain" ContentTemplate="{DynamicResource TabCtnts}" ItemTemplate="{DynamicResource TabHdr}" />
</DockPanel>
The cs code is:
public partial class Window3 : Window
{
public Window3()
{
InitializeComponent();
List<Model> models = new List<Model>();
models.Add(new Model { ID = 1, Name = "Jack", Title = "Title_1" });
models.Add(new Model { ID = 2, Name = "Joe", Title = "Title_2" });
sheetMain.ItemsSource = models;
}
}
public class Model
{
public int ID { get; set; }
public string Title { get; set; }
public string Name { get; set; }
}
The result picture is:
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.