Using UWP BackgroundSizing

WinUI XAML

4 years ago

Windows 10 17763 SDK added an interesting property called BackgroundSizing to all controls with a Background. Let's see what it can do. BackgroundSizing is useful for controls with a transparent or semi-transparent Border as it can control whether or not the background of the control extends underneath the border. Suppose we have the following XAML:

By not specifying the BackgroundSizing attribute, the default value is used - InnerBorderEdge. This means the background does not extend beyond the inner edge of the border:

InnerBorderEdge BackgroundSizing example - background does not extend under the border

InnerBorderEdge BackgroundSizing

Now let's change the BackgroundSizing to OuterBorderEdge:

In this case, the background ImageBrush will extend below the border and thanks to the fact that BorderBrush is set to be semi-transparent, it will blend with the background and create a nice effect:

OuterBorderBrush BackgroundSizing - background extends below the border

OuterBorderBrush BackgroundSizing

The BackgroundSizing property is available when targeting Windows 10 build 17763 and newer, but as soon as WinUI 3.0 is released, it will be available for all supported versions of Windows 10!

Source code

A sample project for this article is available on my GitHub.