我一直在构建一个wpf用户控件来充当数据导航器,以便在各种表单上使用。它从视图模型中获取基础ICollectionView作为其数据源,就像网格等表单上的其他控件一样。网格上的视图设置如此;
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
,典型的表格可能是这样的:
现在我想要做的是确定底层视图集合何时是脏的,这样我就可以使用该信息来启用导航器控件上的保存按钮等禁用功能。我已经尝试了CurrentChanging和CollectionChanged。前者我认为这两者中更有前途,虽然当我在网格上选择或创建新行时会触发,但是当我更改单元格中的内容时它不会触发。我想知道在启用保存按钮之前,行或行实际上是脏的。
由于