Add TabItem in tabcontrol at runtime using Silverlight
Hi friends, i am new to silverlight app. i have created tabcontrol with 4 tabitem .Name of the tabitems are like tab1 tab2 tab3 tab4 . i need to add one more tabitem at run item . it added successfully by following code
TabItem tabItem = new TabItem();
tabItem.Header = "tab5"; tabControl.Items.Add(tabItem);
my problem is, tab5 added next to tab4 . but my requirement is ,it should added next my current selected tabitem .that is, if am in tab1 it should between tab1 and tab2 and so on. i have searched in msdn and goggle 开发者_如何学Pythondidn't get anything.Possible give some guidance to get my solution. i don't like to use third parties control .Please guide me to finish this issue
The TabControl
exposes a SelectedIndex
property, this will tell you the index of the currently visible tab within the TabControl.Items
, simply Insert
after that index. For example:
tabControl.Items.Insert(tabControl.SelectedIndex + 1, tabItem);
TabItem tabItem = new TabItem();
tabItem.Header = "tab5";
tabControl1.Items.Insert(tabControl1.SelectedIndex + 1, tabItem);
Use tabControl.Items.Insert(index, item)
精彩评论