Find answers for the most frequently asked questions
How do I dynamically hide and unhide tabs in a TabControl ?
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).
How do I validate the current tab before selection changes to another tab on user click?
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#]
publicTabValidation()
{
InitializeComponent();
foreach (TabItem item in tabControl1.Items)
{
item.PreviewLostKeyboardFocus += new KeyboardFocusChangedEventHandler(item_PreviewLostKeyboardFocus);
}
}
voiditem_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
// sender is the TabItem.if (this.ValidateTab() == false)
e.Handled = true;
}
Share with