dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
6.88k stars 1.14k forks source link

Inconsistent border color rendering with black Background and BorderBrush. #9107

Open TamilarasanGunasekaran opened 1 month ago

TamilarasanGunasekaran commented 1 month ago

Description

When setting both the Background and BorderBrush colors to black within a border element, an unexpected behavior occurs where an inner border in gray appears only on the top and bottom sides. This inconsistency in border color rendering contradicts the expected behavior and may lead to visual discrepancies in UI design.

Reproduction Steps

Issue Screenshot:

image

WPFDemo.zip

Expected behavior

The gray border color should not be displayed.

Actual behavior

The gray border color is displayed.

Regression?

No response

Known Workarounds

No response

Impact

No response

Configuration

No response

Other information

No response

miloush commented 1 month ago

Note that this is not "gray border", it is the background color peeking through space between the square's border and square's background. If you use SnapsToDevicePixels="True", this reproduces in a stable way with DPI 125%: image

I agree that should certainly not happen, at least not with this property set.

As a workaround, you can use UseLayoutRounding="true" (e.g. on the Grid) (or ensure the background behind the square is of matching color if possible).

huiliuss commented 3 weeks ago

Hi, miloush's solution is great.


<Grid VerticalAlignment="Center" HorizontalAlignment="Center" SnapsToDevicePixels="True">

...

</Grid>

Have you checked the solution? If you still have issues please describe in more detail.

miloush commented 3 weeks ago

@huiliuss It is not as much as solution as a workaround. Also as I showed above, SnapsToDevicePixels is not enough, which is potentially a bug.