I am trying to add Tabs to a tab control in WPF but nothing appears on the control at runtime. I have tried following the examples I keep seeing. Right now this is what I have but it isn't working
_myConnection.Open();
SqlDataReader myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
MessageBox.Show(myReader["SectionName"].ToString());
TabItem newTabItem = new TabItem
{
Header = myReader["SectionName"].ToString(),
Name = myReader["SectionID"].ToString()
};
TabMain.Items.Add(newTabItem);
}
_myConnection.Close();
TabMain.SelectedIndex = 0;
Best Answer
You can add tabs dynamically by using the following code.
Add the following code to declare tab control instance globally.
Now, add the following code to the loaded event of the tab control.
I have used a button to add new tabs for the existing tab control.
Following is my tab control xaml view.
Finally, using this you can add any amount of tabs dynamically to the existing tab control.
Hope this fulfill your need.