c# - Using a single control as content of multiple tabs -


i have textbox, tabcontrol , simple object called someobject.

i create list<someobject> object , fill dynamic number of someobject.

foreach someobject in list create tabitem give name same value name property in someobject.

here commented code of doing

public partial class mainwindow : window {      list<someobject> list;     textbox textbox = new textbox() { name = "textbox1" };     public mainwindow()     {         initializecomponent();         //create test list of someobject         list = new list<someobject>()         {             new someobject() {name = "italian", description = "italian description"},             new someobject() {name = "german", description = "german description"},             new someobject() {name = "french", description = "french description"}         };          //add tab item each object         foreach(someobject someobj in list)         {             tabcontrol1.items.add(new tabitem { name = someobj.name,header = someobj.name });         }      }      //on selected tabitem changed event set content of tab items null , set content of selected tabitem textbox textbox1     private void tabcontrol1_selectionchanged(object sender, selectionchangedeventargs e)     {          foreach(tabitem tab in (sender tabcontrol).items)         {             tab.content = null;         }         string someobjectnameproperty = ((sender tabcontrol).selecteditem tabitem).name;         textbox.text = list.find(obj => obj.name == someobjectnameproperty).description;         ((sender tabcontrol).selecteditem tabitem).content = textbox;     }      //someobject class     class someobject     {         public string name { get; set; }         public string description { get; set; }     }  } 

i did of above because don't want have textbox control inside each tab item, code working there more convienient way achieve same result wpf?

this example demonstration.


Comments