The below article shows how to create dynamic tabs in WPF, that in each tab it will add just one text box.
private TabItem AddTabItem()
{
int count = _tabItems.Count;
// create new tab item
TabItem tab = new TabItem();
tab.Header = string.Format("Tab {0}", count);
tab.Name = string.Format("tab{0}", count);
tab.HeaderTemplate = tabDynamic.FindResource("TabHeader") as DataTemplate;
tab.MouseDoubleClick += new MouseButtonEventHandler(tab_MouseDoubleClick);
// add controls to tab item, this case I added just a textbox
TextBox txt = new TextBox();
txt.Name = "txt";
tab.Content = txt;
// insert tab item right before the last (+) tab item
_tabItems.Insert(count - 1, tab);
return tab;
}
http://www.codeproject.com/Articles/493538/Add-Remove-Tabs-Dynamically-in-WPF
what can I do for adding some complex controls that their positions are fixed instead of just 1 text box? can I create a user control for this purpose? so how can I add the user control to tab control?
Best Answer
Try the next steps:
Add a user control (Lets say in ComplexControl.xaml)
Create a class
Map them together so when you have a myComplexContolClass in your app visually it will be the UserControl from 1. The map can be done with DataTemplate:
Or
Add it to your code: