Hi,
try following demo. You can add TabItem via code or from XAML-file.
MainWindow
<Window x:Class="WpfApp1.Window019"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp019"
mc:Ignorable="d"
Title="Window019" Height="450" Width="800">
<Window.DataContext>
<local:ViewModel/>
</Window.DataContext>
<Grid>
<TabControl ItemsSource="{Binding TabItems}"/>
</Grid>
</Window>
ViewModel
using System.Collections.Generic;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
namespace WpfApp019
{
public class ViewModel
{
public ViewModel() => AddTabItems();
public List<TabItem> TabItems { get; set; } = new List<TabItem>();
private void AddTabItems()
{
TabItems.Add(new TabItem() { Header = "tab1", Content = new TextBlock() { Text = "Tab Data 1" } });
using (Stream rdr = new FileStream("Window019TabItem.xaml", FileMode.Open)) TabItems.Add((TabItem)XamlReader.Load(rdr));
}
}
}
XAML TabItem
<TabItem xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Header="tab2" >
<Grid>
<TextBlock Text="Tab Data 2" />
</Grid>
</TabItem>