public void PushNewTab(Page Content) { TabItem tab = AppResources.CloneXaml <TabItem>(TabDeclarationCached); (tab.Content as Frame).Content = Content; var closeButton = (((tab.Header as Border).Child as DockPanel).Children[0] as Button); var title = (((tab.Header as Border).Child as DockPanel).Children[1] as TextBlock); title.Text = Content.Title; (tab.Content as Frame).Tag = tab; (tab.Content as Frame).Navigating += MainWindow_Navigating; closeButton.Tag = tab; closeButton.Click += CloseButtonClick; TabSwitcher.Items.Insert(TabSwitcher.Items.Count - 1, tab); int x = TabSwitcher.Items.Count - 1; Dispatcher.BeginInvoke((Action)(() => TabSwitcher.SelectedItem = tab)); }
public MainWindow() { InitializeComponent(); ApplicationMainWindow = this; TabDeclarationCached = AppResources.XamlToString(TabSwitcher.Items[0] as TabItem); }