*Edit*
After thinking about this again, my original reply was wrong because the user doesn't necessarily right-click on the selected tab. I see your dilemma, but there's a solution (well, at least one)...
In the MenuItem Click handler, the sender is a MenuItem. Its DataContext will be a reference to the object providing the data item for the tab item. You just need to remove that object from the collection that is providing data to the tab control. For example, here's how I tested it...
<UserControl x:Class="WPFTester.TabControlTestPage"
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"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<TabControl x:Name="tabControlMain" Loaded="tabControlMain_Loaded" >
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Title}">
<TextBlock.ContextMenu>
<ContextMenu>
<MenuItem Header="Remove" Click="MenuItem_Remove_Click">
<!--<MenuItem.Icon>
<Image Width="20" Height="20" Source="..\Resources\remove.png" Stretch="Fill" />
</MenuItem.Icon>-->
</MenuItem>
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<TextBlock Text="{Binding Content}" />
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
</Grid>
</UserControl>
public partial class TabControlTestPage : UserControl
{
public TabControlTestPage()
{
InitializeComponent();
}
private TabDataTestList tabDataTestList = new TabDataTestList();
private void tabControlMain_Loaded(object sender, RoutedEventArgs e)
{
tabControlMain.ItemsSource = tabDataTestList;
}
private void MenuItem_Remove_Click(object sender, RoutedEventArgs e)
{
tabDataTestList.Remove(((sender as MenuItem).DataContext) as TabData);
}
}
public class TabData
{
public string Title { get; set; }
public string Content { get; set; }
}
public class TabDataTestList : ObservableCollection<TabData>
{
public TabDataTestList()
{
this.Add(new TabData() { Title = "Item 1", Content = "Content for item 1" });
this.Add(new TabData() { Title = "Item 2", Content = "Content for item 2" });
this.Add(new TabData() { Title = "Item 3", Content = "Content for item 3" });
this.Add(new TabData() { Title = "Item 4", Content = "Content for item 4" });
this.Add(new TabData() { Title = "Item 5", Content = "Content for item 5" });
}
}