0

I have been building a wpf user control to act as a data navigator for use on various forms. It takes as it's data source the underlying ICollectionView from a view model as do other controls on forms like grids. The view on the grid is setup like so;

Public Shared ReadOnly DataIcvProperty As DependencyProperty = DependencyProperty.Register("DataIcv", GetType(ICollectionView), GetType(DataNavigator), New FrameworkPropertyMetadata(Nothing, New PropertyChangedCallback(AddressOf OnDataIcvChanged)))


<Description("The CollectionView (as an ICollectionView) to be passed to the DataNavigator control"), Category("Vtl DataNavigator Main Properties")>
Public Property DataIcv As ICollectionView
    Get
        Return CType(GetValue(DataIcvProperty), ICollectionView)
    End Get
    Set(ByVal Value As ICollectionView)
        SetValue(DataIcvProperty, Value)

    End Set
End Property

Private Shared Sub OnDataIcvChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
    Dim dn As DataNavigator = CType(d, DataNavigator)
    dn.RecordsCount = dn.GetRecordCount
    dn.Records.Text = dn.RecordsCount.ToString

    dn.UpdateUi()

    If e.OldValue IsNot Nothing Then
        RemoveHandler dn.DataIcv.CollectionChanged, AddressOf dn.OnDataIcvCollectionChanged
        RemoveHandler dn.DataIcv.CurrentChanged, AddressOf dn.OnDataICVCurrentChanged
        RemoveHandler dn.DataIcv.CurrentChanging, AddressOf dn.OnDataIcvCurrentChanging
    End If
    If e.NewValue IsNot Nothing Then
        AddHandler dn.DataIcv.CollectionChanged, AddressOf dn.OnDataIcvCollectionChanged
        AddHandler dn.DataIcv.CurrentChanged, AddressOf dn.OnDataICVCurrentChanged
        AddHandler dn.DataIcv.CurrentChanging, AddressOf dn.OnDataIcvCurrentChanging
    End If

End Sub

Private Sub OnDataICVCurrentChanged(ByVal sender As Object, ByVal e As EventArgs)

    Record.Text = (DataIcv.CurrentPosition + 1).ToString
    UpdateUi()
End Sub

Private Sub OnDataIcvCurrentChanging(ByVal sender As Object, ByVal e As EventArgs)
    'MessageBox.Show("I've Changed")
End Sub

Private Sub OnDataIcvCollectionChanged(ByVal sender As Object, ByVal e As EventArgs)
    MessageBox.Show("I've Changed")
End Sub

and a typical form might be like this:

enter image description here

Now what I would like to be able to do is determine when the underlying view collection is dirty so that I can use that info to enable of disable things like the save button on the navigator control. I have tried both CurrentChanging, and CollectionChanged. The former I would have thought was the more promising of the two, and whilst it does fire when I select or create new rows on the grid it does not fire when I change the contents in a cell. I would like to know that a row, or rows are actually dirty before enabling the save button.

Thanks

Dom Sinclair
  • 2,458
  • 1
  • 30
  • 47
  • 1
    http://msdn.microsoft.com/en-us/library/system.windows.data.binding.notifyonsourceupdated%28v=vs.110%29.aspx – eran otzap Dec 23 '14 at 16:22
  • Thanks for the information. But if I add my navigator to a form and then bind an ICollectionView to it with with NotifyOnTargetUpdated set to true and the address of a handler, won't that handler have to be in the form, and Not in the datanavigator so I'm still left with trying to tell the navigator (which is a stand alone control) that an edit has occurred..correct? – Dom Sinclair Dec 23 '14 at 16:33

0 Answers0