Public Partial classMainwindow:window { PublicMainWindow () {InitializeComponent (); } Private voidTabcontrol_selectionchanged_1 (Objectsender, SelectionChangedEventArgs e) { } Private intA; Private voidMenuitem_click_1 (Objectsender, RoutedEventArgs e) {TabItem B=NewTabItem ();//Create a new option firstB.header ="window"+ A;//Create a new name, such as window 2Aaa. Items.Add (b);//Put the built in there .Aaa. SelectedIndex = A +1;//Create a new windowa++;//Increment } Private voidMenuitem_click_2 (Objectsender, RoutedEventArgs e) { This. Close ();//turn the button off . } }}
<window x:class="wpf_ Click New to pop up the new window. MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="Http://schemas.microsoft.com/winfx/2006/xaml"Title="window"height=" -"Width="525"> <Grid> <Menu> <menuitem header="file"> <menuitem header="New Window"click="Menuitem_click_1"></MenuItem> <menuitem header="Close"click="menuitem_click_2"></MenuItem> </MenuItem> <menuitem header="Help"> </MenuItem> <tabcontrol name="AAA"Horizontalalignment=" Left"height="299"Width="518"> <tabitem header="window"> <grid background="#FFE5E5E5"/> </TabItem> </TabControl> </Menu> </Grid> </Window>
WPF Click New to pop up a new window