I’m working on some feature for my IDE, clicking some treeviewitem, will change the current displayed tab. I’m trying to do that, but no luck. What am I doing wrong?
How can I set the desired tab to be focued?
Here’s the code:
void tr_ViewOtherClass(object sender, MouseButtonEventArgs e)
{
string tagToView = ((TreeViewItem) sender).Tag.ToString();
TabItem currentTab = ((TabItem) (tabControl.SelectedItem));
if (tagToView != currentTab.Tag.ToString())
{
TabItem tabToView = null;
for (int i = 0; i < tabControl.Items.Count; i++)
{
tabToView = ((TabItem) (tabControl.Items[i]));
if (tabToView.Tag.ToString() == tagToView)
break;
}
classCodes[currentTab.Tag.ToString()] = ((TextEditor) currentTab.Content).Text;
currentTab = tabToView;
}
}
When you assign a value to the
currentTabvariable, it does not modifytabControl.SelectedItem.You must assign directly
tabControl.SelectedItemif you want to change its value ;currentTabis equivalent to a pointer, and modifying its value only modifies the value pointed by the local variable.