In #4218 we imported `IElementFactory` from WinUI which is broadly analogous to a recycling datatemplate for lists. In Avalonia this implement `IDataTemplate` in order to have a common base class for all types of data templates.
The problem with this is that `IDataTemplate` already had a `SupportsRecycling` property which is incompatible with the way recycling is implemented in `IElementFactory`. Instead, introduce an `IRecyclingDataTemplate` to signal data templates that support recycling.
And remove child selection when a `TreeViewItem` is un-expanded.
This is necessary because we don't get enough information about a materialized `TreeViewItem` to select it when materialized, so the `SelectionModel` and `TreeViewItem` selection state gets out of sync.
Update `TreeItemContainerGenerator.Index` when a `TreeViewItem` is added to or removed from the logical tree. This ensures that removed `TreeViewItem`s won't try to add duplicate containers to the index.
Fixes#2985
Previously it wasn't clear which constructor on `InstancedBinding` must be called for a particular binding mode. Refactored the constructors:
- We now have a single public ctor which takes an `ISubject`, as a subject can be used for all binding modes.
- Instanced bindings with other sources such as single values and `IObservables` are now constructed via static methods which only allow the correct sources for that binding mode
Added an `IDataTemplateHost` interface with a `IsDataTemplatesInitialized` property to prevent the need for allocating empty `DataTemplates` collections for many controls.
- Set `InheritanceParent` before Parent so that control doesn't
initially inherit the wrong DataContext
- Don't set `InheritanceParent` when setting `Parent` if
`InheritanceParent` already set
- Added `IDataTemplate.SupportsRecycling`