Add TabItem in tabcontrol at runtime using Silverlight

故事扮演 提交于 2020-02-28 08:23:31

问题


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 didn'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


回答1:


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);



回答2:


TabItem tabItem = new TabItem();
tabItem.Header = "tab5";
tabControl1.Items.Insert(tabControl1.SelectedIndex + 1, tabItem);



回答3:


Use tabControl.Items.Insert(index, item)



来源:https://stackoverflow.com/questions/6449639/add-tabitem-in-tabcontrol-at-runtime-using-silverlight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!