Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

How to add event handler to the tab of a TabItem?

$
0
0
I am trying to add an event to allow someone to change the header on a tab item. When someone hits New from the file menu, I want the program to add a new tab with a default header. They can then click the header and change the name. I have a function that calls a dialog box that allows them to enter then new name. My question is, how do I assign the new function to the mouse click event on the tab of the TabItem?

Thanks,

Ed

The code that I have is as follows:
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e) {
            leftDock.Width = 0;
            mainDock.Margin = new Thickness(0, 23, 0, 23);
            if ((mainTabControl.FindName("New Doc") == null)) {
                AddNewTab("New Doc", mainTabControl);
            }
            


        }

        private void AddNewTab(string tabName, TabControl aTabControl) {
            TabItem newTab = new TabItem();
            newTab.Header = tabName;
            aTabControl.Items.Add(newTab);
            aTabControl.SelectedItem = (TabItem)aTabControl.FindName(tabName);
            
            return;
        }

        private void TabItemChangeName(object sender, RoutedEventArgs e) {
            Views.InputWindow nameWindow = new Views.InputWindow();
            namewindow.Owner = this;
            namewindow.ShowDialog();

            if (namewindow.DialogResult == true) {
                ((TabItem)sender).Header = namewindow.inputTextBox.Text;
            }
        }
    }

Viewing all articles
Browse latest Browse all 51036

Trending Articles