Search code examples
wpftreeviewselectoritemscontrol

Why does the WPF TreeView control inherit from ItemsControl instead of Selector?


Looking at the inheritance chart for WPF controls I notice something unexpected for the TreeView control. Other controls that allow user selection inherit from either the Selector or MultiSelector base class. This makes sense as the Selector class adds selection capabilities to the base ItemsControl class. So I was expected that the TreeView would likewise inherit from that same class, but it does not. It inherits from ItemsControl directly. Any ideas why?


Solution

  • It's because the selection of the tree-items must be managed along the whole hierarchy, and not only along the root-level items. The Selector class keeps track of a flat-list. The fact is that an hierarchy structure must be treated in a particular way.