OnPropertyChanged fired after TabControl PreviewSelectionChanged

2 posts, 0 answers
  1. Rob Ainscough
    Rob Ainscough avatar
    262 posts
    Member since:
    Jan 2010

    Posted 11 Aug 2016 Link to this post

    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:EventTrigger EventName="PreviewSelectionChanged">
                <ei:CallMethodAction TargetObject="{Binding}" MethodName="CheckSetupTabChange" />


    My MVVM class property:

    Private _SiteFacilityName As String
    Public Property SiteFacilityName() As String
            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)
                ' 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
                            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.



  2. Martin Ivanov
    Martin Ivanov avatar
    2360 posts

    Posted 16 Aug 2016 Link to this post

    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. 

    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top