I'm trying to implement some code that prevents the changing of a Tab without first saving changes made to the working set of controls. I'm doing MVVM with binding to my class properties (where the OnPropertyChanged is).
I have a method that determines if property values have been changed and sets an IsDirty flag.
The problem is that the OnPropertyChanged isn't triggered until AFTER I've moved to a new Tab item. As such the Dirty flag is not set and my code doesn't prevent the tab change from happening because it thinks nothing IsDirty. Only AFTER the tab change (PreviewSelectionChanged) event fires ... so I don't really know how I can handle validating any data BEFORE allowing a tab change?
<!-- Setup Tab -->
<
telerik:RadTabControl
x:Name
=
"SetupTabControl"
Grid.Row
=
"1"
Grid.Column
=
"0"
Grid.ColumnSpan
=
"7"
TabStripPlacement
=
"Left"
SelectedIndex
=
"{Binding SelectedSetupIndex, Mode=TwoWay}"
TabOrientation
=
"Vertical"
>
<!-- Events for TabControl -->
<
i:Interaction.Triggers
>
<
i:EventTrigger
EventName
=
"PreviewSelectionChanged"
>
<
ei:CallMethodAction
TargetObject
=
"{Binding}"
MethodName
=
"CheckSetupTabChange"
/>
</
i:EventTrigger
>
</
i:Interaction.Triggers
>
My MVVM class property:
Private
_SiteFacilityName
As
String
Public
Property
SiteFacilityName()
As
String
Get
Return
_SiteFacilityName
End
Get
Set
(
ByVal
value
As
String
)
GeneralInfoTabDirty(_SiteFacilityName, value)
_SiteFacilityName = value
OnPropertyChanged(
New
PropertyChangedEventArgs(
"SiteFacilityName"
))
End
Set
End
Property
The event method being called BEFORE the OnPropertyChanged
Public
Sub
CheckSetupTabChange(sender
As
Object
, e
As
RadSelectionChangedEventArgs)
Try
' NOTE:
' Set e.Handled to TRUE to prevent the tab change event from happening
' e.Handled = True
' e.Handled = False (default) will all continuation of Tab Control event to next Tab selected
' NOTE: SelectedIndex will be for the New tab item, NOT the old (leaving) tab item -- means have to track the Prior Index manually
' NOTE: This event is fired BEFORE OnPropertyChange?? The OnPropertyChange happens AFTER this event
If
sender IsNot
Nothing
Then
If
e IsNot
Nothing
Then
' Only want to process events from SetupTabControl
If
e.Source.Name =
"SetupTabControl"
Then
If
Me
.GeneralInfoTabIsDirty
Then
e.Handled =
True
SaveGeneralInfoChanges()
End
If
Any hints on how I can work this? Optimally I'd like to see the OnPropertyChange trigger BEFORE any SL5 Interactions (perhaps this is whey SL5 Interactivity DLLs were and still are considered "experimental" ... half finished by Microsoft and the fully abandoned).
Cheers, Rob.