Add Support for `BackgroundSizing` from WinUI
See original GitHub issueIs your feature request related to a problem? Please describe.
WinUI added a new property to templated controls and border: BackgroundSizing
. This property does not exist in WPF.
Describe the solution you’d like
The usage of this property controls how a border is drawn relative to a background:
InnerBorderEdge
background inside edge the border line orOuterBorderEdge
background extended to the outside edge of the border- [Optional/New]
CenterBorder
to render as Avalonia currently works (backwards-compatibility)
This property is important when working with semi-transparent border brushes (which became prevalent with Fluent v1 in Windows). The way Avalonia works now in this regard is not only different from both WPF and WinUI, it fundamentally cannot work with semi-transparent border brushes. Avalonia presently draws the “stroke” right on the “fill” edge. This is Skia’s default but it means half of the the “stroke” is inside the shape and the other half of the “stroke” is outside the shape.
Also, @amwx noted (with current Avalonia):
The other issue is that because of this, Avalonia’s border rendering is different whether the simple or complex path is taken - the simple path uses Skia’s default and the complex path is equivalent to InnerBorderSizing (I think).
Rendering should never differ for these cases.
Also keep in mind this has been discussed a number of places recently:
- The most detailed over at FluentAvalonia here: https://github.com/amwx/FluentAvalonia/issues/262#issuecomment-1366925225
- Discussion here: https://github.com/AvaloniaUI/Avalonia/discussions/9233
- https://github.com/AvaloniaUI/Avalonia/pull/9488#issuecomment-1321263107
- https://github.com/AvaloniaUI/Avalonia/issues/11424#issuecomment-1559674121
Describe alternatives you’ve considered
There aren’t many alternatives here. The way Avalonia renders borders now is fundamentally broken for transparent border brushes.
Additional context
I will take a look at updating Border to support this and adding the property to the necessary controls. However, I don’t have experience with Avalonia’s composition rendering system and I won’t have a low-level implementation. The solution planned is complex geometries like what is required now for corner radius and thickness differences in BorderRenderHelper
.
Issue Analytics
- State:
- Created 8 months ago
- Reactions:3
- Comments:8 (6 by maintainers)
Top GitHub Comments
Yes, it’s planned. It missed the cutoff for 11.0 I think but will follow with 11.x as a non breaking change. To make it non-breaking one additional background sizing mode will be added compared to WinUI:
CenterBorder
.Some background in another issue: https://github.com/AvaloniaUI/Avalonia/issues/11424#issuecomment-1559674121
Linking here to keep the full discussion together.