<Grid x:Name="LayoutRoot" Background="White">
<sdk:TabControl Height="300" Name="tabControl1" VerticalAlignment="Top" HorizontalAlignment="Left" Width="219">
<sdk:TabItem>
<sdk:TabItem.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Tab1"/>
<Ellipse Width="20" Height="20" Fill="Blue"/>
</StackPanel>
</sdk:TabItem.Header>
<Ellipse Width="20" Height="20" Fill="Blue"/>
</sdk:TabItem>
</sdk:TabControl>
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="325,0,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click"/>
<TextBox Height="23" HorizontalAlignment="Left" Margin="240,0,0,0" Name="textBox1" VerticalAlignment="Top" Width="79" />
<ListBox Height="262" HorizontalAlignment="Left" Margin="240,38,0,0" Name="listBox1" VerticalAlignment="Top" Width="148" />
</Grid>
string name = textBox1.Text.Trim();
StackPanel sp1 = new StackPanel
{
Orientation = Orientation.Horizontal
};
TabItem tab = new TabItem
{
Name = "tab" + TabCount,
Header = sp1
};
TextBlock tb1 = new TextBlock
{
Text = "tab" + name
};
Image ii = new Image
{
Source = new BitmapImage(new Uri("Images/QQ截图20140507193021.jpg", UriKind.Relative))
};
Button btn = new Button
{
//按钮背景是图片
//Content = ii,
Tag = "tab" + TabCount,
Content = "X",
Width = 14,
Height = 14,
Padding = new Thickness(0),
BorderThickness = new Thickness(0),
};
sp1.Children.Add(tb1);
sp1.Children.Add(btn);
this.tabControl1.Items.Add(tab);
TabCount++;
btn.Click += new RoutedEventHandler(button_Click);
}
void button_Click(object sender, RoutedEventArgs e)
{
Button b = sender as Button;
this.Parent as TabItem).Parent as TabControl).Items.Remove((this.Parent as TabItem));
TabItem item = this.tabControl1.FindName(b.Tag.ToString()) as TabItem;
tabControl1.Items.Remove(item);
TabCount--;
}