The TabItems have a Visibility property which can be set to Collapsed (no space will be reserved for this tab) or Hidden (not rendered, but space will be reserved for this tab).
Unfortunately, WPF doesn’t provide a straight forward way of validating a tab page’s content before switching to a new tab, in the first version. One workaround is to listen to the TabItem’s PreviewLostKeyboardFocus event and mark it as Handled as shown below.
[C#]
public TabValidation()
{
InitializeComponent();
foreach (TabItem item in tabControl1.Items)
{
item.PreviewLostKeyboardFocus += new KeyboardFocusChangedEventHandler(item_PreviewLostKeyboardFocus);
}
}
void item_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
// sender is the TabItem.
if (this.ValidateTab() == false)
e.Handled = true;
}