I would like to make a new ObservableCollection called datagridTime and insert into this ObservableCollection only records that match so lets say we haveTime `ObservableCollection`Arrival | Departure---------------------------------10 2010 3010 10Time2 `ObservableCollection`Arrival | Departure---------------------------------10 2010 3010 20datagridTime `ObservableCollection`Arrived | Departed---------------------------------10 2010 30推荐答案这是一个简短的示例应用程序,可以完成您想要的操作.Here is a short sample App which should do what you want. 魔术部分是这样:public ObservableCollection<Person> People1 { get; } = new ObservableCollection<Person>(){ new Person("Donald", "Duck"), new Person("Daisy", "Duck"), new Person("Jack", "Daniels")};public ObservableCollection<Person> People2 { get; } = new ObservableCollection<Person>(){ new Person("Donald", "Duck"), new Person("Daisy", "Duck"), new Person("Jim", "Beam")};public IEnumerable<Person> PeopleInBothCollections{ get { foreach (var person in People1) { if (People2.Any(x => x.FirstName == person.FirstName && x.LastName == person.LastName)) { yield return person; } } }}无论何时引发 PropertyChanged 事件,它都会更新您的第三个列表: When ever you raise the PropertyChanged-event it should update your third list:这是示例的链接: https://github.com/timunie/MahApps.Metro.Examples/tree/master/src/MahApps.Metro.Examples/IntersectTwoLists 这篇关于将2个可观察集合中的匹配值组合到第3个[WPF]中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-28 01:30