TabControl.SelectionChanged
-
HI i"m trying to make a simple task when a tab is changing in a tab control, i want to check if a save should be done. and if so - ask the user if he wants to save or stay in the same tab (keep editing for example) i can't cancel the tab selection in the SelectionChanged event what can i do? Thanks, Yanai
-
HI i"m trying to make a simple task when a tab is changing in a tab control, i want to check if a save should be done. and if so - ask the user if he wants to save or stay in the same tab (keep editing for example) i can't cancel the tab selection in the SelectionChanged event what can i do? Thanks, Yanai
Yanai, Just handle the
PreviewMouseLeftButtonDown
event for theTabControl
. Then check if theSource
of theRoutedEvent
is aTabItem
. Perform your testing to see if you want to cancel the event and if so use,e.Handled = True
to handle the event which will cancel the tab page switching.Private Sub tcPages_PreviewMouseLeftButtonDown(ByVal sender As Object, _
ByVal e As System.Windows.Input.MouseButtonEventArgs) _
Handles tcPages.PreviewMouseLeftButtonDownIf TypeOf e.Source Is TabItem Then 'perform your test here 'if you want to keep editing then use this code e.Handled = True End If
End Sub
Cheers, Karl
» CodeProject 2008 MVP » Microsoft MVP - Client App Dev My Blog | Mole's Home Page | MVP ProfileJust a grain of sand on the worlds beaches.