First, create a form, and then add the menu bar and the original TabControl tab to the form
<Grid> <Menu> <menuitem header="file"click="Menuitem_click_3"> <menuitem header="Open a new window"click="Menuitem_click_1"></MenuItem> <menuitem header="Exit"click="Menuitem_click_4"></MenuItem> </MenuItem> <menuitem header="Help"> <menuitem header="About Us"></MenuItem> </MenuItem> </Menu> <tabcontrol name="TabControl1"Horizontalalignment=" Left"height="337"margin="0,20,0,0"Verticalalignment="Top"Width="572"> <tabitem header="Original Window"> <grid background="#FFE5E5E5"> <textbox horizontalalignment=" Left"height="305"margin="0"textwrapping="Wrap"text=""Verticalalignment="Top"Width="562"/> </Grid> </TabItem> < ;/tabcontrol> </Grid>
Second, when clicking Open a new window, the new window will pop up, and add a full text box in the new window (Adding a text box to the new tab has not been implemented)
Public Partial classMainwindow:window { PublicMainWindow () {InitializeComponent (); } Private inti =0;//define a I used to make the new item name differentTextBox T;//Create a new item and throw the textbox in . Private voidMenuitem_click_1 (Objectsender, RoutedEventArgs e)//Open new Window button{TabItem ti=NewTabItem ();//Create a new tabTi. Header ="New Window"+ (i+1);//Name of new tabTabControl1.Items.Add (TI);//Throw the new tab into the TabControl1.t =NewTextBox ();//To manifest a new text boxT.width =562; T.height=305; //The following is the beginning of adding a text box to the newly created tab//each new window is highlighted by default as a new windowTabcontrol1.selectedindex = i+1; I++; } Private voidMenuitem_click_4 (Objectsender, RoutedEventArgs e)//Close button { This. Close (); } Private voidMenuitem_click_3 (Objectsender, RoutedEventArgs e) { } }
wpf--menu bar and TabControl