0

What I want to do in this example is make the first tab of the tabcontrol disappear and add 2 new tabs dynamically. The new tabs appear but their 'Header' is not showing:

            ItemCollection ic = this.tabControl1.Items;
            TabItem firstTab = (TabItem)ic[0];
            firstTab.Visibility = Visibility.Collapsed;

            TabItem newTab = new TabItem();
            newTab.HeaderTemplate = firstTab.HeaderTemplate;
            newTab.Header = newTab.Name = "test1";
            ic.Add(new TabItem());

            newTab = new TabItem();
            newTab.HeaderTemplate = firstTab.HeaderTemplate;
            newTab.Template = firstTab.Template;
            newTab.ContentTemplate = firstTab.ContentTemplate;
            newTab.Header = newTab.Name = "test2";
            ic.Add(new TabItem());
4

1 回答 1

0

将两者都替换ic.Add(new TabItem());ic.Add(newTab)

像这样:

TabItem newTab = new TabItem();
newTab.HeaderTemplate = firstTab.HeaderTemplate;
newTab.Header = newTab.Name = "test1";
ic.Add(newTab);

newTab = new TabItem();
newTab.HeaderTemplate = firstTab.HeaderTemplate;
newTab.Template = firstTab.Template;
newTab.ContentTemplate = firstTab.ContentTemplate;
newTab.Header = newTab.Name = "test2";
ic.Add(newTab);
于 2013-05-03T19:16:57.563 回答