UIElementCollection和Collection 之间的区别?

时间:2021-03-22 13:27:17

In WPF and Silverlight, we have seen the following classes:

在WPF和Silverlight中,我们看到了以下类:

  • UIElementCollection
  • ItemCollection
  • RowDefinitionCollection
  • ColumnDefinitionCollection
  • PointCollection
  • and a lot more....
  • 还有更多....

Why do they have these classes, one class for each type? Why did they not use generic classes such as Collection<T>?

为什么他们有这些类,每种类型一个类?为什么他们不使用Collection 等泛型类?

Also, I've seen in Silverlight, all of these classes have been derived from PresentationFrameworkCollection<T> , as

另外,我在Silverlight中看到,所有这些类都是从PresentationFrameworkCollection 派生的,如

public sealed class ItemCollection : PresentationFrameworkCollection<Object> 
public sealed class PointCollection : PresentationFrameworkCollection<Object> 
public sealed class IconCollection : PresentationFrameworkCollection<Object> 
//and so on...

If all of these derive from a common class, and I don't see anything public in the derived classes (all of them are empty!), then why did they define them in the first place? I feel that there are some differences which are either declared private or internal in the derived classes. But I don't exactly know.

如果所有这些派生自一个公共类,并且我在派生类中看不到任何公共内容(所有这些都是空的!),那么为什么他们首先定义它们呢?我觉得在派生类中有一些差异被声明为私有或内部。但我不确切知道。

Please help me understanding the design of these classes. In particular, why did they use them instead of generic classes which come with the framework? What are the benefits?

请帮我理解这些课程的设计。特别是,为什么他们使用它们而不是框架附带的泛型类?有什么好处?

1 个解决方案

#1


6  

They internally work different, based on the use case they were designed for. For example, UIElementCollection doesn't just hold the elements, but also makes sure they are added and removed from the corresponding visual tree...

它们在内部工作方式不同,基于它们的用例。例如,UIElementCollection不仅保存元素,还确保它们从相应的可视化树中添加和删除...

#1


6  

They internally work different, based on the use case they were designed for. For example, UIElementCollection doesn't just hold the elements, but also makes sure they are added and removed from the corresponding visual tree...

它们在内部工作方式不同,基于它们的用例。例如,UIElementCollection不仅保存元素,还确保它们从相应的可视化树中添加和删除...