开发者

removing first tab before window shows

Hi i currently have a window that has a tab contro开发者_如何学Cl. What i am trying to do is remove the tab that is first created by my xaml then call my c# code that creates a new tab.

Currently i have

public MainWindow()   
        {
            InitializeComponent();
             newTab();                
             tabControl1.Items.Remove(tabControl1.SelectedValue="tabItem1");
        }

The first tab has the value "tabItem1" but it doesn't seem to remove the tab. I have also tried doing a remove on index 0 but that didn't work either.

Thanks!


if you are sure that you want to do it this way... give the tabItem a name, and remove it by using its reference ...

<TabControl Name="tabControl1" >
    <TabItem Header="tabItem1" Name="tabItem1">
        <Grid />
    </TabItem>
    <TabItem Header="tabItem2" Name="tabItem2">
        <Grid />
    </TabItem>
</TabControl>

and remove the Tab with:

tabControl1.Items.Remove(tabItem1);


Give Remove() whatever the x:Name of the TabItem object is:

public MainWindow()   
{
    InitializeComponent();
    newTab();                
    tabControl1.Items.Remove(tabItem1);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜