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:
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;
}
}
}