[ad_1]
嗨伙计。
我有一个观察集。
我使用了 CollectionChanged 事件。
但此事件仅在添加新项目或删除项目时引发。
那么如何检测某个项目是否已编辑呢?
(当然,最好还检测哪个项目获得了版本。)
有什么帮助吗?
我尝试过的:
网络
Imports System.Collections.ObjectModel Public Class Person Public Property Name As String End Class Public listORG As New ObservableCollection(Of Person)() Sub New() InitializeComponent() Dim names As New List(Of String) From {"Alice", "Bob", "Charlie", "David", "Eve", "Frank", "Grace", "Harry", "Ivy", "Jack"} Dim rand As New Random() For i As Integer = 0 To 29 Dim index As Integer = rand.Next(names.Count) Dim person As New Person With {.Name = names(index)} listORG.Add(person) Next i ' Bind ObservableCollection to DataGrid in WPF DGlistORG.ItemsSource = listORG AddHandler listORG.CollectionChanged, AddressOf listORG_CollectionChanged End Sub Private Sub listORG_CollectionChanged(sender As Object, e As System.Collections.Specialized.NotifyCollectionChangedEventArgs) MsgBox("Updated") End Sub
解决方案1
您无法使用 ObservableCollection 判断对象是否已更改。 执行此操作的方法是使用 INotifyPropertyChanged 并在更改属性中的值时引发 PropertyChanged 事件。
[ad_2]
コメント