Observable Collection 不支持AddRange
您可以将整个列表添加到现有列表的功能。
顺便说一句,如果你所有的 observable 集合都是 T 类型,你可以使用它foreach
来遍历并执行adding
,如下所示:
var observableCollection1 = new ObservableCollection<string>();
var observableCollection = new ObservableCollection<string>();
foreach (var element in observableCollection1)
{
observableCollection.Add(element);
}
但是,据我了解,您正在尝试将 an 添加observable collection of type department
到 adifferent type T
中,除非您尝试将其添加到 a 中,否则这是不可能的observable collection of simply, objects
。警告:请注意,之后您可能需要装箱/拆箱。
Code Snippet:
var observableCollection_Department = new ObservableCollection<Department>();
var observableCollection_Employee = new ObservableCollection<Employee>();
var observableCollection_Boss = new ObservableCollection<Boss>();
var observableCollection = new ObservableCollection<object>();
foreach (var element in observableCollection_Department)
{
observableCollection.Add(element);
}
foreach (var element in observableCollection_Employee)
{
observableCollection.Add(element);
}
foreach (var element in observableCollection_Boss)
{
observableCollection.Add(element);
}