That change fix very tricky bug. Our case:
We have DataTemplate that contains DataGrid inside it. And Datagrid has an AttachedProperty (that deserve us to observe changes in Datagrid's SelectedItems). which work through event subscription. Memory leaks happen (and the logic for observe selected items breaks) when DataTemplate switches DataContext.
Instead of simply wiping all control themes and styles that are applied to a control, we can now just remove the `ValueFrame`s which relate to the control theme that was changed.
To do this, added `ValueFrame.FramePriority` which encodes both the `BindingPriority` and source of the frame (style, control theme, templated parent control theme).
Applying styling in the constructor isn't a good idea as demonstrated by #8549..
Instead apply styling when showing a window, or if it's needed call `ApplyStyling` manually, e.g. in unit tests.
Fixes#8549
- Removes the `IStyler` service and the `Styler` implementation
- Moves the logic for applying styles and control themes into `StyledElement`
- Removes the style `TryAttach` method from the public API
- Removes style caching for now - this will need to be added back
Now tries to simulate an application with a lot of styles applied at different points in the logical tree.
Make `StyledElement.ApplyStyling` a public API in order to do this.
Added SKPaintCache.Return which only returns the paint and does not reset.
Removed PaintWrapper._disposePaint.
Removed all method call's references to setting PaintWrapper._disposePaint.