Instead of each control listening to its parent `ResourcesChanged` event, use the logical tree to propagate `ResourcesChanged` events:
- When attaching to the logical tree, piggyback on the `AttachedToLogicalTree` traversal
- At other times, propagate by calling `NotifyResourcesChanged`
Split resource nodes into two types:
- `IResourceHost` represents controls and `Application`
- `IResourceProvider` represents resource dictionaries and styles, these are owned by `IResourceHost`s
Dynamic resources are now always resolved from an `IResourceHost`: if an `IResourceProvider` doesn't have a host then a dynamic resource in the resource provider will not be resolved. Resource providers no longer have a `ResourcesChanged` event, instead they notify their `IResourceHost` owner of a resource change by calling the `NotifyHostedResourcesChanged` method.
In the case of #3708, the sanity check fails because the parent call to `SetParent` hasn't yet completed - it's the setting of `InheritanceParent` on the parent that causes the child to get attached.
- Don't use Rx in the styling system. Instead introduces `IStyleActivator` which is like an `IObservable<bool>`-lite in order to cut down on allocations.
- #nullable enable on touched files
- Don't use Rx in the styling system. Instead introduces `IStyleActivator` which is like an `IObservable<bool>`-lite in order to cut down on allocations.
- #nullable enable on touched files
The root of our logical tree is denoted by `IStyleRoot` for historical reasons: before #1594, styling was defined in `Avalonia.Styling` but the logical tree was defined in `Avalonia.Controls`. The styling system needed a root but because it was lower-level than the logical tree it had to define its own root type which was then repurposed for use by the logical tree.
Since #1594 the logical tree is defined in `Avalonia.Styling` as well so we might as well call `IStyleRoot` what it is: the logical tree root.
- When detaching set `Parent` to `null` before raising the `DetachedFromLogicalTree` event
- To do this, we need to store the logical root in the control so that e.g. a child control can be detached in a `DetachedFromLogicalTree` handler
- Add `Source` and `Parent` properties to `LogicalTreeAttachmentEventArgs` to give more context on what caused the attachment/detachment
It was only needed for pseudoclasses. Move pseudoclass registration to an engine that doesn't require `AvaloniaProperty.Initialized`, implemented in `PseudoclassEngine`.
`IResourceDictionary` was defined as an `IDictionary<object, object>` but in various places we only accepted a `string` as the resource key. Fix this inconsistency and always use `object` as a resource key.
Fixes#2456
During initial layout, `TemplatedParent` is read tens of thousands of times. This being a styled property that used `inherits: true` meant that it was showing up in profiling as taking up a significant amount of time.
Make `TemplatedParent` a direct property so that reading it is a simple property access. This doesn't actually complicate the code much at all as once set the property value doesn't change, so `inherited: true` semantics are not that important.
Don't notify a non-inheritance child that the data context has begun changing, because it won't receive the accompanying end change notification.
Fixes#1245.
When a data context changes, it should be notified to all descendant controls who inherit the data context. This allows the `SelectingItemsControl` to defer setting the selected item until the `DataContext` has changed for the whole tree.
Renamed `OnDataContextChanging`/`OnDataContextChanged` to `OnDataContextBeginUpdate`/`OnDataContextEndUpdate` because `DataContextChanged` is now called from the property changed notification.
Fixes#507.
Previously, if the user overrode `OnAttachedToLogicalTree` or `OnDetachedFromLogicalTree` and forgot to call the base implementation, the events wouldn't be raised. It's very important that these events get raised so moved the code to raise them to `OnAttachedToLogicalTreeCore`/`OnDetachedFromLogicalTreeCore`.