I am doing something like the following to prevent a tab selection from changing:
tabControl.Items.CurrentChanging += new CurrentChangingEventHandler(Items_CurrentChanging);
void Items_CurrentChanging(object sender, CurrentChangingEventArgs e)
{
if( dataIsInvalid )
{
// Show some popup message
var item = ((ICollectionView)sender).CurrentItem;
e.Cancel = true;
tabControl.SelectedItem = item; // !! This causes the CurrentChanging event to happen twice !!
// But without this the visual tree does not update! :(
}
}
However the problem that I am seeing right now is that the last line above causes a CurrentChanging event to happen a second time, and my popup message is displayed twice. Not only that, it is displayed the second time after bringing another window into focus first, and then putting focus back on my tab control's window. Any ideas why this could be happening?
--EDIT--
It looks like I should really only need e.Cancel
and not require updating the SelectedItem
again. However the visual tree is not updated unless I do this. Is there any way I can ensure the visual tree of the tab control is updated after e.Cancel
occurs, without having to update the SelectedItem
?