你好,
你可以在B窗体的button Click事件中创建一个A窗体对象,然后new一个新的TabItem 对象,通过 Tabcontrol.Items.Add()方法来动态添加tabitem。
这里是一个示例:
A窗体:
<Window x:Class="WpfApplication1.WindowA"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WindowA" Height="650" Width="1125">
<StackPanel>
<TabControl Name="mytab">
<TabItem Header="tabitem1">
<Image Source="Resources\test.png"/>
</TabItem>
</TabControl>
</StackPanel>
</Window>
B窗体:
>>>>>>>>>>>>> .xaml file <<<<<<<<<<<<<<<<<<
<Window x:Class="WpfApplication1.WindowsB"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WindowsB" Height="200" Width="400">
<StackPanel ">
<Button Click="Button_Click">Click</Button>
</StackPanel>
</Window>
>>>>>>>>>>>>> .cs file <<<<<<<<<<<<<<<<<<
private void Button_Click(object sender, RoutedEventArgs e)
{
WindowA myWindowA = new WindowA();
TabItem t = new TabItem();
t.Header = "tabitem2";
Button bt = new Button();
bt.Content = "I am a new Button!";
t.Content = bt;
myWindowA.mytab.Items.Add(t);
myWindowA.Show();
}
Lisa Zhu [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.