Skip to content

Fix SimpleTheme focus adorner contrast in dark mode - #21753

Merged
MrJul merged 3 commits into
AvaloniaUI:mainfrom
iamvalenciia:codex/fix-simple-theme-focus-adorner
Jul 23, 2026
Merged

Fix SimpleTheme focus adorner contrast in dark mode#21753
MrJul merged 3 commits into
AvaloniaUI:mainfrom
iamvalenciia:codex/fix-simple-theme-focus-adorner

Conversation

@iamvalenciia

@iamvalenciia iamvalenciia commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

What does the pull request do?

Updates SimpleTheme's default focus adorner to use the theme-aware ThemeForegroundBrush.

What is the current behavior?

The default focus rectangle always uses a black stroke, which has insufficient contrast against dark backgrounds.

What is the updated/expected behavior with this PR?

The focus rectangle uses the foreground brush for the active theme: black in the light theme and #FFDEDEDE in the dark theme.

Verified with:

  • Avalonia.Controls.UnitTests: 3,636 total, 3,635 passed, 0 failed, 1 pre-existing skipped test.

How was the solution implemented (if it's not obvious)?

Replaced the hard-coded Stroke=Black value in SimpleTheme's AdornerLayer control theme with a dynamic reference to ThemeForegroundBrush.

Checklist

  • Added unit tests (not applicable; the focused theme-value test was removed per review because it would only restate the configured resource value).
  • Added XML documentation to any related classes? (Not applicable; no public API changes.)
  • Consider submitting a PR to https://github.com/AvaloniaUI/avalonia-docs with user documentation (Not applicable; bug fix only.)

Breaking changes

None.

Obsoletions / Deprecations

None.

Fixed issues

Fixes #18312

@iamvalenciia
iamvalenciia force-pushed the codex/fix-simple-theme-focus-adorner branch from 40ca69e to 92ce498 Compare July 10, 2026 19:48
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.2.999-cibuild0067424-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@cla-avalonia

cla-avalonia commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator
  • All contributors have signed the CLA.

@iamvalenciia

Copy link
Copy Markdown
Contributor Author

@cla-avalonia agree

@MrJul MrJul added bug backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Jul 11, 2026
public class AdornerLayerTests : ScopedTestBase
{
[Fact]
public void Default_Focus_Adorner_Uses_Dark_Theme_Foreground()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I'm usually always asking for more tests, I think this case one is redundant: it does not test the AdornerLayer itself but rather the value of a single property on a given theme, which would need to be updated if we decide to change the color. In other words, it won't catch anything. Please remove it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed as requested. The PR now only contains the XAML theme change. Thanks!

@MrJul MrJul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@MrJul
MrJul added this pull request to the merge queue Jul 23, 2026
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.2.999-cibuild0067643-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

Merged via the queue into AvaloniaUI:main with commit fb09d61 Jul 23, 2026
9 checks passed
MrJul pushed a commit that referenced this pull request Jul 29, 2026
* Add regression test for SimpleTheme focus adorner

* Fix SimpleTheme focus adorner in dark mode

* Remove redundant focus adorner test
@MrJul MrJul added backported-12.1.x and removed backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tab move focus dashed box can not see in dark mode while using <SimpleTheme/>

4 participants