Tommy
Tommy

Reputation: 583

Programmatically close TabItem in WPF

How the hell do you programmatically close a TabItem in a Windows 8 WPF Desktop TabControl?

There are no options in Intellisense, and the only things that appear in search results are custom implementations of either the TabControl or the TabItem.

Why can't we just do something like tabControl.SelectedItem.Close();?

Upvotes: 0

Views: 2347

Answers (2)

David Goshadze
David Goshadze

Reputation: 1437

I think that closing is the same as removing TabItem from TabControl

Edit: For Ex:

tabControl1.Items.RemoveAt(tabControl1.SelectedIndex);

Upvotes: 5

Andrey Gordeev
Andrey Gordeev

Reputation: 32449

You cannot close it. TabItem is not closeable. You can just hide it:

tabControl.SelectedItem.Visibility = System.Windows.Visibility.Collapsed

Upvotes: 1

Related Questions