question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add Support for `BackgroundSizing` from WinUI

See original GitHub issue

Is 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:

  1. InnerBorderEdge background inside edge the border line or
  2. OuterBorderEdge background extended to the outside edge of the border
  3. [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:

  1. The most detailed over at FluentAvalonia here: https://github.com/amwx/FluentAvalonia/issues/262#issuecomment-1366925225
  2. Discussion here: https://github.com/AvaloniaUI/Avalonia/discussions/9233
  3. https://github.com/AvaloniaUI/Avalonia/pull/9488#issuecomment-1321263107
  4. 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:open
  • Created 8 months ago
  • Reactions:3
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
robloocommented, May 17, 2023

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.

0reactions
robloocommented, May 23, 2023

Some background in another issue: https://github.com/AvaloniaUI/Avalonia/issues/11424#issuecomment-1559674121

Linking here to keep the full discussion together.

Read more comments on GitHub >

github_iconTop Results From Across the Web

BackgroundSizing Enum (Windows.UI.Xaml.Controls)
Defines constants that specify how far an element's background extends in relation to the element's border.
Read more >
Control.BackgroundSizing Property - UWP
Gets or sets a value that indicates how far the background extends in relation to this element's border.
Read more >
Using UWP BackgroundSizing - Martin Zikmund
Windows 10 17763 SDK added an interesting property called BackgroundSizing to all controls with a Background . Let's see what it can do....
Read more >
Fixing Broken DefaultButtonStyle in Windows UI (WinUI ...
Anyhow, here's the fix – you can copy and paste this into your App.xaml and it will replace the existing DefaultButtonStyle defined by...
Read more >
How to add an animation to a button when its command ...
In a WinUi 3 application I created a custom Command that implements both an Executed event and a HasExecuted property with change notification....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found