This is a migrated thread and some comments may be shown as answers.

OnPropertyChanged fired after TabControl PreviewSelectionChanged

1 Answer 252 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Rob Ainscough
Top achievements
Rank 1
Rob Ainscough asked on 11 Aug 2016, 08:33 PM

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.

 

 

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 16 Aug 2016, 12:07 PM
Hello Rob,

I am not sure where the properties from your view model are bound so I cannot reproduce the described behavior. Note that the PropertyChanged event will be fired at different moment depending on what property is bound. So, depending on the properties that you want to mark as dirty, you might need to use different strategies. Can you tell me what properties you want to validate and how they are bound to the tab control?

About the event, originally PreviewSelectionChanged will be fired before the selected tab is changed so you should be able to check the properties in the event handler. 

Regards,
Martin
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
General Discussions
Asked by
Rob Ainscough
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or