Instead of looking for an `IStyledElement` as an anchor, look for an `IResourceHost` because `Application` doesn't implement `IStyledElement` but it does implement `IResourceHost` and this interface has everything we need.
When `_target.Owner` was null, the resource observable produced a `null` which may not be valid for the target property, resulting in an exception . Although the exception is caught, it slows things down.
When subscribing to a `PropertySetterBindingInstance`, if the owner style is not active then there's no need to subscribe to the inner observable as this can cause resource lookups etc. Part of fixing #5027.
Just need to call `BindingValue<T>.FromUntyped` instead of doing a conditional, because otherwise we run the risk of passing `UnsetValue` to the `BindingValue<T>` ctor which will throw in that case.
Make `StaticResource` and `DynamicResource` automatically convert `Color`s to `ImmutableSolidColorBrush`es and add a `ColorToBrushConverter` for use by bindings.
To do this I made `GetResourceObservable` accept an optional conversion function.
`_subscription` was being used twice: for the subscription from the `PropertySetterBindingInstance` to the control (line 69) and from the subscription to the source binding to the `PropertySetterBindingInstance` (line 151).
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.