Skip to content

TextBlock Foreground change re-measures and re-shapes the text #25408

Open

Description

@MartinZikmund

What would you like to be added? 💡

A Foreground change on a TextBlock or one of its runs should only repaint the text. That includes an in-place brush color change, such as a ColorAnimation on the brush. Today it invalidates measure, and the text is shaped again.

Why is this needed? 🤔

TextBlock.OnForegroundChanged calls InvalidateTextBlock(), which calls InvalidateMeasure(), and MeasureOverride always re-parses the text. Run.OnForegroundChanged invalidates its inlines the same way. In WinUI, a brush change on text only dirties render.

The cost scales with the number of TextBlocks sharing the brush. Flipping the color of a brush shared by 2,000 TextBlocks costs about 20 ms of UI-thread time and 14.8 MB of allocations per change, and renders two frames.

The ListViewItemPresenter chrome in #25389 sets the multi-select check glyph's Foreground on every selection change.

For which platforms 📱💻🖥️

Skia (all heads)

Anything else we need to know? 💬

Found while profiling GridView selection for #25389.

Activity

  1. added
    7.1
    on Oct 14, 2026
  2. removed
    7.1
    on Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/performancekind/enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions