private void Window_Loaded(object sender, RoutedEventArgs e) { MenuItem item = new MenuItem() { Header = "插件" }; ms.Items.Add(item); foreach (IPlugin plugin in myPlugins) { MenuItem subItem = new MenuItem() { Header = plugin.Text, Tag = plugin }; subItem.Click += (s, arg) => { IPlugin pluginTemp = (IPlugin)((MenuItem)s).Tag; UserControl u = pluginTemp.Do(); foreach (TabItem app in workSpace.Items) { if ((string)app.Tag == pluginTemp.Text) { workSpace.SelectedItem = app; return; } } CloseableTabItem tabItem = new CloseableTabItem(pluginTemp.Text); tabItem.Tag = pluginTemp.Text; tabItem.Content = u; tabItem.TabItemClosing += tabItem_OnClose; workSpace.Items.Add(tabItem); workSpace.SelectedIndex = workSpace.Items.Count - 1; }; item.Items.Add(subItem); } }
public void tabItem_OnClose(object sender, RoutedEventArgs e) { CloseableTabItem wt = sender as CloseableTabItem; }