Skip to content

[Windows]Fix: Label.FormattedText does not clear previous TextHighlighters - #36608

Merged
kubaflo merged 3 commits into
dotnet:inflight/currentfrom
SubhikshaSf4851:Fix-36519
Jul 17, 2026
Merged

kubaflo merged 3 commits into
dotnet:inflight/currentfrom
SubhikshaSf4851:Fix-36519

Conversation

@SubhikshaSf4851

Copy link
Copy Markdown
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment whether this change resolves your issue. Thank you!

This pull request addresses an issue where updating a Label's FormattedText on Windows did not clear previous text highlighting, causing stale highlighter ranges to persist and affect new text. The fix ensures that highlighter state is properly reset when the formatted text changes. Additionally, a new test is added to verify this behavior across platforms, with extra checks for Windows.

Description of Change

Bug fix:

  • FormattedStringExtensions.cs: Ensures that TextBlock.TextHighlighters is cleared whenever the inlines are updated, preventing highlighter leakage when FormattedText is changed.

Testing improvements:

  • FormattedStringTests.cs: Adds a new test, UpdatingFormattedTextClearsPreviousHighlights, to confirm that updating a label’s formatted text clears any previous highlight/background color state, with specific validation for the Windows platform.

Issues Fixed

Fixes #36519

Tested the behavior in the following platforms

  • Windows
  • Android
  • iOS
  • Mac
Before Issue Fix After Issue Fix
BeforeFix36519.mp4
AfterFix36519.mp4

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 36608

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 36608"

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label Jul 16, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hey there @@SubhikshaSf4851! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@dotnet-policy-service dotnet-policy-service Bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Jul 16, 2026
@SubhikshaSf4851 SubhikshaSf4851 changed the title [WIP][Windows]Fix: Label.FormattedText does not clear previous TextHighlighters [Windows]Fix: Label.FormattedText does not clear previous TextHighlighters Jul 16, 2026
@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Jul 16, 2026
kubaflo pushed a commit that referenced this pull request Jul 16, 2026
The Windows Controls device-test gate could observe a per-category result
file on disk (Test-Path true) a moment before the device-test app finished
flushing its XML. Get-Content then read empty/partial content, casting it to
[xml] yielded $null, and the subsequent .SelectNodes() call threw the opaque
'You cannot call a method on a null-valued expression'. The gate surfaced that
as an unactionable ENV ERROR with no results (observed on #36608 across all
retries, without-fix and with-fix).

Get-WindowsDeviceTestResultSummary now retries the read briefly to absorb the
write race — recovering the REAL results so a transient race no longer collapses
to an inconclusive verdict — and throws a clear, descriptive message when the
file is genuinely empty or malformed (app crashed before writing). The outcome
for a true crash stays INCONCLUSIVE (safe, non-blocking), but the diagnostic is
now actionable.

Adds Pester coverage for the empty and malformed cases, and loads the
ConvertTo-DeviceTestCount helper in the test harness so the existing aggregation
test passes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 15d2af20-e4ab-4e88-9011-cfbd83513bc0
Comment thread src/Controls/src/Core/Platform/Windows/Extensions/FormattedStringExtensions.cs Outdated
@MauiBot MauiBot added s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review) labels Jul 16, 2026
@kubaflo

This comment has been minimized.

MauiBot

This comment was marked as outdated.

@MauiBot MauiBot removed the s/agent-review-in-progress AI review is currently running for this PR label Jul 16, 2026
@sheiksyedm
sheiksyedm marked this pull request as ready for review July 16, 2026 12:37
Copilot AI review requested due to automatic review settings July 16, 2026 12:37
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a Windows-specific Label.FormattedText bug where TextBlock.TextHighlighters were not cleared when rebuilding inlines, causing stale highlight ranges (and potential TextHighlighter accumulation) to persist across FormattedText updates. Adds a device test to validate that updating formatted text removes prior highlight/background state, with an additional native assertion on Windows.

Changes:

  • Windows: clear TextBlock.TextHighlighters whenever FormattedStringExtensions.UpdateInlines rebuilds the Inlines collection.
  • Tests: add UpdatingFormattedTextClearsPreviousHighlights to verify stale highlight/background state does not persist after updating Label.FormattedText (including a Windows-only native TextHighlighters check).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Controls/src/Core/Platform/Windows/Extensions/FormattedStringExtensions.cs Clears TextHighlighters alongside Inlines.Clear() so prior span highlight ranges don’t leak into subsequent FormattedText updates.
src/Controls/tests/DeviceTests/Elements/FormattedStringTests.cs Adds a regression test that asserts highlight color is present initially and removed after updating to non-highlighted formatted text (plus Windows-only TextHighlighters collection assertions).

Copilot AI review requested due to automatic review settings July 16, 2026 12:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@kubaflo

This comment has been minimized.

MauiBot

This comment was marked as outdated.

@MauiBot MauiBot removed the s/agent-review-in-progress AI review is currently running for this PR label Jul 16, 2026
Copilot AI review requested due to automatic review settings July 17, 2026 06:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@vishnumenon2684

Copy link
Copy Markdown
Contributor

/azp run maui-pr-uitests , maui-pr-devicetests

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Jul 17, 2026
kubaflo pushed a commit that referenced this pull request Jul 17, 2026
The Copilot review gate verifies device-test PRs by running the test's whole
[Category] (e.g. Category=Shell). If any *unrelated* test in that category
APP_CRASHes (XHarness exit 80), the run dies on BOTH the with-fix and
without-fix sides, so the gate can only report INCONCLUSIVE — even though the
PR's own 1-2 target methods are fine (e.g. #36616, #36581, #36608).

XHarness's Xunit runner already supports an include filter by class
(TestRunner.SkipClass(fqcn, isExcluded:false) -> CreateClassFilter matches
ITypeInfo.Name == Type.FullName). This wires that up so the gate runs ONLY the
PR's test class, isolating the verdict from crashing siblings in the category.

Additive and safe:
- New, separate `IncludeClasses` host arg (Android instrumentation arg /
  iOS+MacCatalyst env via --set-env). The existing `TestFilter=Category=...`
  path is untouched, so the main maui-pr-devicetests pipeline and the Windows
  category parser are byte-identical (they never emit/read the new arg).
- Empty by default (TestOptions.IncludeClassNames = []), so normal runs skip
  the new code path entirely.
- Safe failure: if the FQCN matches 0 tests the run reports 0 tests ->
  INCONCLUSIVE, no worse than today.

Detect-TestsInDiff now derives the fully-qualified class name (namespace +
class) for DeviceTest groups and passes it through verify-tests-fail ->
Run-DeviceTests as `IncludeClasses`, while $group.Filter still carries the
whole-Category value for Windows and fallback. Wired for Core + Controls
device tests (Android + iOS/MacCatalyst); Windows keeps category behaviour.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 15d2af20-e4ab-4e88-9011-cfbd83513bc0

@MauiBot MauiBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

AI Review Summary

@SubhikshaSf4851 — new AI review results are available based on this last commit: 30f500f. To request a fresh review after new comments or commits, comment /review rerun.

Gate Inconclusive Confidence Low Platform Windows


🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix

Gate Result: ⚠️ INCONCLUSIVE

Platform: WINDOWS · Base: main · Merge base: 0188c0c6

Test Without Fix (expect FAIL) With Fix (expect PASS)
📱 FormattedStringTests (UpdatingFormattedTextClearsPreviousHighlights) Category=Label ⚠️ ENV ERROR ⚠️ ENV ERROR
🔴 Without fix — 📱 FormattedStringTests (UpdatingFormattedTextClearsPreviousHighlights): ⚠️ ENV ERROR · 325s

No log file found

🟢 With fix — 📱 FormattedStringTests (UpdatingFormattedTextClearsPreviousHighlights): ⚠️ ENV ERROR · 154s

No log file found

⚠️ Failure Details

  • ⚠️ FormattedStringTests (UpdatingFormattedTextClearsPreviousHighlights) without fix: Windows device test result file 'artifacts\log\TestResults-Microsoft_Maui_Controls_DeviceTests_Label.xml' is empty or not valid XML (the device-test app likely crashed or exited before writing results).
  • ⚠️ FormattedStringTests (UpdatingFormattedTextClearsPreviousHighlights) with fix: Windows device test result file 'artifacts\log\TestResults-Microsoft_Maui_Controls_DeviceTests_Label.xml' is empty or not valid XML (the device-test app likely crashed or exited before writing results).
📁 Fix files reverted (1 files)
  • src/Controls/src/Core/Platform/Windows/Extensions/FormattedStringExtensions.cs

📱 UI Tests — Button,Label,Layout

Detected UI test categories: Button,Label,Layout

✅ Deep UI tests — 351 passed, 0 failed across 3 categories on platform-pool agent (replaces in-process counts above).

🧪 UI Test Execution Results (deep, platform pool)

Category Tests Snapshot diffs
Button 69/70 ✓ —
Label 91/94 ✓ —
Layout 191/195 ✓ —
📎 Download drop-deep-uitests artifact (TRX + snapshot diffs)

📋 Pre-Flight — Context & Validation

Issue: #36519 - [Windows, 10.0.71] Windows Label.FormattedText does not clear previous TextHighlighters when updating spans, leading to overlapping highlights & memory leaks
PR: #36608 - [Windows]Fix: Label.FormattedText does not clear previous TextHighlighters
Platforms Affected: Windows
Files Changed: 1 implementation, 1 test

Key Findings

  • Issue #36519 reports that Windows Label.FormattedText updates leave previous TextBlock.TextHighlighters in place when new formatted spans are assigned, causing stale highlighting and retaining old TextHighlighter instances.
  • PR fix changes src/Controls/src/Core/Platform/Windows/Extensions/FormattedStringExtensions.cs to clear textBlock.TextHighlighters whenever UpdateInlines rebuilds formatted text.
  • Regression coverage was added in src/Controls/tests/DeviceTests/Elements/FormattedStringTests.cs for updating from highlighted formatted text to unhighlighted formatted text, including a Windows native TextHighlighters assertion.
  • Gate result supplied by caller is inconclusive due to build/environment error; per instruction, this pre-flight does not treat it as a failing fix and does not re-run gate verification.

Code Review Summary

Verdict: NEEDS_DISCUSSION
Confidence: low
Errors: 0 | Warnings: 0 | Suggestions: 0

Key code review findings:

  • ℹ No code correctness findings were identified by the independent code-review pass.
  • ℹ Blast radius is localized to Windows formatted-label text rendering; no startup or static state impact.
  • ℹ CI/required-check state was not fully verifiable in the unauthenticated environment, so the code-review verdict cannot be LGTM even though the code change is targeted.

Fix Candidates

# Source Approach Test Result Files Changed Notes
PR PR #36608 Clear TextBlock.TextHighlighters at the start of Windows formatted-text inline rebuild and reuse the cached highlighter collection for additions. ⚠️ INCONCLUSIVE (Gate) src/Controls/src/Core/Platform/Windows/Extensions/FormattedStringExtensions.cs, src/Controls/tests/DeviceTests/Elements/FormattedStringTests.cs Original PR fix; gate could not build/run in prior step.

🔬 Code Review — Deep Analysis

Code Review — PR #36608

Independent Assessment

What this changes: Windows FormattedStringExtensions.UpdateInlines now clears TextBlock.TextHighlighters before rebuilding formatted-label inlines (FormattedStringExtensions.cs:61-62) and reuses the cached collection when adding new highlighters (:102). A device test verifies updating Label.FormattedText removes stale highlight state (FormattedStringTests.cs:61-102).

Inferred motivation: Prevent stale Windows TextHighlighter ranges from accumulating when a formatted label is updated.

Reconciliation with PR Narrative

Author claims: Fixes #36519: Windows Label.FormattedText did not clear old highlighters, causing visual overlap and leaks.
Agreement/disagreement: Agrees. The issue root cause names the same missing clear, and the PR applies it at the correct rebuild point.

Prior Review Reconciliation

No prior ❌ Error code findings found. Prior human comments requested using the cached textHighlighters local for later additions; current code does that. MauiBot ❌ markers were CI/gate related, not unresolved code findings.

Blast Radius Assessment

  • Runs for all instances: Only Windows labels using formatted text when UpdateInlines runs.
  • Startup impact: No.
  • Static/shared state: No.
  • Platform scope: Windows text rendering path; confidence capped below high.

CI Status

  • Required-check result: gh pr checks --required unavailable because gh is unauthenticated.
  • Public checks observed: maui-pr success; Build Analysis, maui-pr-uitests, and maui-pr-devicetests failing.
  • Classification: likely unrelated/infra or unrelated platform failures (macOS timeout, binlog read EndOfStream, MacCatalyst BadExit, Android/iOS UI failures). Windows device-test leg passed. Full required-check classification remains limited by unauthenticated environment.
  • Action taken: Invoked azdo-build-investigator; used public GitHub/AzDO REST where available; confidence capped low.

Findings

No ❌ Errors, ⚠️ Warnings, or 💡 Suggestions from code review. Expert reviewer also reported no high-confidence inline findings.

Failure-Mode Probing

  • Updating highlighted formatted text to unhighlighted formatted text: old TextHighlighters are cleared before new runs are added.
  • Updating highlighted formatted text to plain text: existing plain-text path already clears highlighters.
  • Initial handler connection: clearing an empty collection is safe; new highlighters are added normally.
  • Null/default FormattedText: existing tuple conversion handles null spans; no new null path introduced.

Verdict: NEEDS_DISCUSSION

Confidence: low
Summary: Code change looks correct and targeted, with appropriate regression coverage. I cannot give LGTM because CI is red and required-check status could not be fully verified in this unauthenticated environment.


🛠️ Fix — Analysis & Comparison

Fix Candidates

# Source Approach Test Result Files Changed Notes
1 try-fix Track and remove only MAUI-owned Windows TextHighlighter instances via attached state. ❌ Fail 2 files Built with 0 errors, but Windows device-test runner produced empty/invalid Label XML; more complex than PR fix.
2 try-fix Clear Windows TextBlock.TextHighlighters in the Controls Label.FormattedText mapper before rebuilding text. ❌ Fail 3 files Built with 0 errors, same empty/invalid Label XML; weaker encapsulation because direct UpdateInlines callers remain unprotected.
3 try-fix Reconcile TextBlock.TextHighlighters to the desired current formatted-string projection without a blanket clear. ❌ Fail 1 file Built with 0 errors, same empty/invalid Label XML; more complex than PR fix.
PR PR #36608 Clear TextBlock.TextHighlighters at the start of Windows formatted-text inline rebuild. ⚠️ INCONCLUSIVE (Gate) 2 files Original PR; gate could not build/run in prior step.

Cross-Pollination

Model Round New Ideas? Details
gpt-5.5 expert 1 Yes Candidate 1: MAUI-owned highlighter lifecycle tracking.
gpt-5.5 expert 2 Yes Candidate 2: mapper-level rich-text reset.
gpt-5.5 expert 3 Yes Candidate 3: deterministic highlighter reconciliation in UpdateInlines.
gpt-5.5 expert 4 No NO NEW IDEAS: viable fixes reduce to clearing stale native highlighters during UpdateInlines, tracking/removing MAUI-owned highlighters, mapper-level cleanup before text remap, or reconciling the desired highlighter set; remaining options are relocations or disproportionately broad rewrites.

Exhausted: Yes
Selected Fix: PR #36608 — Among explored candidates, no alternative passed the Windows test command or was demonstrably better. Code review found the PR fix targeted and simpler; all alternatives added complexity or weaker encapsulation.


📝 Recommended PR Title & Description

Assessment: ✏️ Recommend updating — the current description is accurate and detailed, but the title does not follow the [Platform] Component: What changed formula and still describes the pre-fix bug state.

Recommended title

[Windows] Label: Clear TextHighlighters when FormattedText changes

Recommended description

This pull request addresses an issue where updating a `Label`'s `FormattedText` on Windows did not clear previous text highlighting, causing stale highlighter ranges to persist and affect new text. The fix ensures that highlighter state is properly reset when the formatted text changes. Additionally, a new test is added to verify this behavior across platforms, with extra checks for Windows.

### Description of Change

**Bug fix:**
* [`FormattedStringExtensions.cs`](diffhunk://#diff-3846573c00e8c480581599035bcc2e2aa18da8b62da4d0304c52b6e1b970fa7aR61): Ensures that `TextBlock.TextHighlighters` is cleared whenever the inlines are updated, preventing highlighter leakage when `FormattedText` is changed.

**Testing improvements:**
* [`FormattedStringTests.cs`](diffhunk://#diff-24cf35347d91a39e18539e140d96549832bb6897cbfcd80ae3d0acbd96f5f192R53-R103): Adds a new test, `UpdatingFormattedTextClearsPreviousHighlights`, to confirm that updating a label's formatted text clears any previous highlight/background color state, with specific validation for the Windows platform.

### Issues Fixed

Fixes #36519

### Tested the behavior in the following platforms

- [x] Windows
- [ ] Android
- [ ] iOS
- [ ] Mac

| Before Issue Fix | After Issue Fix |
|----------|----------|
| <video src="https://github.com/user-attachments/assets/2c4e9dd6-7dde-445d-8900-02fd86ba383a"> | <video src="https://github.com/user-attachments/assets/8983aca5-672e-4d8d-911e-6470fd463ee9"> |

🏁 Report — Final Recommendation

Comparative Fix Report — PR #36608

Candidate ranking

Rank Candidate Result Assessment
1 pr ⚠️ Gate inconclusive Best candidate. Clears Windows TextBlock.TextHighlighters inside FormattedStringExtensions.UpdateInlines, the same place that rebuilds native inlines and creates new MAUI highlighters. It is localized, simple, and protects all formatted-string inline rebuild callers.
2 pr-plus-reviewer ⚠️ Gate inconclusive Equivalent to pr; the expert reviewer produced no actionable source changes, so this candidate has no behavioral or code-quality advantage over the raw PR fix.
3 try-fix-3 ❌ Fail Reconciles desired highlighters instead of blanket clearing. It keeps cleanup encapsulated in UpdateInlines, but is more complex than the PR and still failed the recorded Windows test command.
4 try-fix-1 ❌ Fail Tracks MAUI-owned highlighters with attached state and removes only those. This avoids clearing possible external highlighters, but adds lifecycle state and changes plain-text cleanup behavior; it also failed the recorded Windows test command.
5 try-fix-2 ❌ Fail Clears highlighters from the Controls Label.FormattedText mapper. This is less well encapsulated because direct UpdateInlines callers remain unprotected, and it failed the recorded Windows test command.

Comparison

The raw PR fix addresses the root cause at the narrowest useful layer: Windows formatted-text projection. Every time MAUI rebuilds formatted inlines, it also resets the corresponding native highlighter collection before adding highlighters for the current spans. This is easier to reason about than tracking ownership state or reconciling highlighter objects, and it avoids the mapper-level candidate's coverage gap.

The STEP 5a try-fix candidates all failed their recorded regression command with an invalid or empty Windows device-test result file. Even though those failures may reflect the same local runner environment problem seen in the gate, the recorded result is still lower confidence than the PR candidate, and the alternatives are not simpler or more complete than the PR fix.

Winner

pr is the winning candidate. It is the simplest complete fix, has no expert-reviewer source findings, has targeted regression coverage, and no try-fix candidate demonstrated a better verified outcome.


🧭 Next Steps — review latest findings

No alternative fix was selected for this run. Review the session findings and CI results before merging.

@MauiBot MauiBot removed the s/agent-review-in-progress AI review is currently running for this PR label Jul 17, 2026
kubaflo pushed a commit that referenced this pull request Jul 17, 2026
Build 14682463 (#36608) flagged 'Prepare UI failure analysis input'
withIssues ('##[error]PowerShell exited with code 1') even though it
logged 'Wrote analysis input (2916 bytes)' one line earlier. The two
'gh pr diff' calls are NATIVE commands whose non-zero exit codes do NOT
trip the surrounding try/catch (that only traps PS terminating errors),
so a benign gh warning leaves $LASTEXITCODE=1 and — with no trailing
exit — pwsh returns that as the script exit code.

Writing the analysis input IS this task's success (it already degrades
gracefully to '(diff unavailable)'/'(could not determine changed files)'
when gh fails), so pin a final 'exit 0' like the early-success paths at
lines 55/67/95 already do. Removes spurious withIssues noise on an
already non-fatal (continueOnError) task.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 15d2af20-e4ab-4e88-9011-cfbd83513bc0
@kubaflo
kubaflo changed the base branch from main to inflight/current July 17, 2026 20:42
@kubaflo
kubaflo merged commit 12a5d41 into dotnet:inflight/current Jul 17, 2026
153 of 163 checks passed
@github-actions github-actions Bot added this to the .NET 10 SR10 milestone Jul 17, 2026
kubaflo pushed a commit that referenced this pull request Jul 22, 2026
…hters (#36608)

<!-- Please keep the note below for people who find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment whether this change resolves your
issue. Thank you!<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!! -->

This pull request addresses an issue where updating a `Label`'s
`FormattedText` on Windows did not clear previous text highlighting,
causing stale highlighter ranges to persist and affect new text. The fix
ensures that highlighter state is properly reset when the formatted text
changes. Additionally, a new test is added to verify this behavior
across platforms, with extra checks for Windows.
### Description of Change
**Bug fix:**
*
[`FormattedStringExtensions.cs`](diffhunk://#diff-3846573c00e8c480581599035bcc2e2aa18da8b62da4d0304c52b6e1b970fa7aR61):
Ensures that `TextBlock.TextHighlighters` is cleared whenever the
inlines are updated, preventing highlighter leakage when `FormattedText`
is changed.

**Testing improvements:**
*
[`FormattedStringTests.cs`](diffhunk://#diff-24cf35347d91a39e18539e140d96549832bb6897cbfcd80ae3d0acbd96f5f192R53-R103):
Adds a new test, `UpdatingFormattedTextClearsPreviousHighlights`, to
confirm that updating a label’s formatted text clears any previous
highlight/background color state, with specific validation for the
Windows platform.



<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #36519 
### Tested the behavior in the following platforms

- [x] Windows
- [ ] Android
- [ ] iOS
- [ ] Mac


| Before Issue Fix | After Issue Fix |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/2c4e9dd6-7dde-445d-8900-02fd86ba383a">
| <video
src="https://github.com/user-attachments/assets/8983aca5-672e-4d8d-911e-6470fd463ee9">
|

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Jul 28, 2026
…hters (#36608)

<!-- Please keep the note below for people who find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment whether this change resolves your
issue. Thank you!<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!! -->

This pull request addresses an issue where updating a `Label`'s
`FormattedText` on Windows did not clear previous text highlighting,
causing stale highlighter ranges to persist and affect new text. The fix
ensures that highlighter state is properly reset when the formatted text
changes. Additionally, a new test is added to verify this behavior
across platforms, with extra checks for Windows.
### Description of Change
**Bug fix:**
*
[`FormattedStringExtensions.cs`](diffhunk://#diff-3846573c00e8c480581599035bcc2e2aa18da8b62da4d0304c52b6e1b970fa7aR61):
Ensures that `TextBlock.TextHighlighters` is cleared whenever the
inlines are updated, preventing highlighter leakage when `FormattedText`
is changed.

**Testing improvements:**
*
[`FormattedStringTests.cs`](diffhunk://#diff-24cf35347d91a39e18539e140d96549832bb6897cbfcd80ae3d0acbd96f5f192R53-R103):
Adds a new test, `UpdatingFormattedTextClearsPreviousHighlights`, to
confirm that updating a label’s formatted text clears any previous
highlight/background color state, with specific validation for the
Windows platform.



<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #36519 
### Tested the behavior in the following platforms

- [x] Windows
- [ ] Android
- [ ] iOS
- [ ] Mac


| Before Issue Fix | After Issue Fix |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/2c4e9dd6-7dde-445d-8900-02fd86ba383a">
| <video
src="https://github.com/user-attachments/assets/8983aca5-672e-4d8d-911e-6470fd463ee9">
|

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Jul 29, 2026
…hters (#36608)

<!-- Please keep the note below for people who find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment whether this change resolves your
issue. Thank you!<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!! -->

This pull request addresses an issue where updating a `Label`'s
`FormattedText` on Windows did not clear previous text highlighting,
causing stale highlighter ranges to persist and affect new text. The fix
ensures that highlighter state is properly reset when the formatted text
changes. Additionally, a new test is added to verify this behavior
across platforms, with extra checks for Windows.
### Description of Change
**Bug fix:**
*
[`FormattedStringExtensions.cs`](diffhunk://#diff-3846573c00e8c480581599035bcc2e2aa18da8b62da4d0304c52b6e1b970fa7aR61):
Ensures that `TextBlock.TextHighlighters` is cleared whenever the
inlines are updated, preventing highlighter leakage when `FormattedText`
is changed.

**Testing improvements:**
*
[`FormattedStringTests.cs`](diffhunk://#diff-24cf35347d91a39e18539e140d96549832bb6897cbfcd80ae3d0acbd96f5f192R53-R103):
Adds a new test, `UpdatingFormattedTextClearsPreviousHighlights`, to
confirm that updating a label’s formatted text clears any previous
highlight/background color state, with specific validation for the
Windows platform.



<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #36519 
### Tested the behavior in the following platforms

- [x] Windows
- [ ] Android
- [ ] iOS
- [ ] Mac


| Before Issue Fix | After Issue Fix |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/2c4e9dd6-7dde-445d-8900-02fd86ba383a">
| <video
src="https://github.com/user-attachments/assets/8983aca5-672e-4d8d-911e-6470fd463ee9">
|

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Aug 7, 2026
…hters (#36608)

<!-- Please keep the note below for people who find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment whether this change resolves your
issue. Thank you!<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!! -->

This pull request addresses an issue where updating a `Label`'s
`FormattedText` on Windows did not clear previous text highlighting,
causing stale highlighter ranges to persist and affect new text. The fix
ensures that highlighter state is properly reset when the formatted text
changes. Additionally, a new test is added to verify this behavior
across platforms, with extra checks for Windows.
### Description of Change
**Bug fix:**
*
[`FormattedStringExtensions.cs`](diffhunk://#diff-3846573c00e8c480581599035bcc2e2aa18da8b62da4d0304c52b6e1b970fa7aR61):
Ensures that `TextBlock.TextHighlighters` is cleared whenever the
inlines are updated, preventing highlighter leakage when `FormattedText`
is changed.

**Testing improvements:**
*
[`FormattedStringTests.cs`](diffhunk://#diff-24cf35347d91a39e18539e140d96549832bb6897cbfcd80ae3d0acbd96f5f192R53-R103):
Adds a new test, `UpdatingFormattedTextClearsPreviousHighlights`, to
confirm that updating a label’s formatted text clears any previous
highlight/background color state, with specific validation for the
Windows platform.



<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #36519 
### Tested the behavior in the following platforms

- [x] Windows
- [ ] Android
- [ ] iOS
- [ ] Mac


| Before Issue Fix | After Issue Fix |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/2c4e9dd6-7dde-445d-8900-02fd86ba383a">
| <video
src="https://github.com/user-attachments/assets/8983aca5-672e-4d8d-911e-6470fd463ee9">
|

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Aug 12, 2026
…hters (#36608)

<!-- Please keep the note below for people who find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment whether this change resolves your
issue. Thank you!<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!! -->

This pull request addresses an issue where updating a `Label`'s
`FormattedText` on Windows did not clear previous text highlighting,
causing stale highlighter ranges to persist and affect new text. The fix
ensures that highlighter state is properly reset when the formatted text
changes. Additionally, a new test is added to verify this behavior
across platforms, with extra checks for Windows.
### Description of Change
**Bug fix:**
*
[`FormattedStringExtensions.cs`](diffhunk://#diff-3846573c00e8c480581599035bcc2e2aa18da8b62da4d0304c52b6e1b970fa7aR61):
Ensures that `TextBlock.TextHighlighters` is cleared whenever the
inlines are updated, preventing highlighter leakage when `FormattedText`
is changed.

**Testing improvements:**
*
[`FormattedStringTests.cs`](diffhunk://#diff-24cf35347d91a39e18539e140d96549832bb6897cbfcd80ae3d0acbd96f5f192R53-R103):
Adds a new test, `UpdatingFormattedTextClearsPreviousHighlights`, to
confirm that updating a label’s formatted text clears any previous
highlight/background color state, with specific validation for the
Windows platform.



<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #36519 
### Tested the behavior in the following platforms

- [x] Windows
- [ ] Android
- [ ] iOS
- [ ] Mac


| Before Issue Fix | After Issue Fix |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/2c4e9dd6-7dde-445d-8900-02fd86ba383a">
| <video
src="https://github.com/user-attachments/assets/8983aca5-672e-4d8d-911e-6470fd463ee9">
|

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 17, 2026
@sheiksyedm sheiksyedm modified the milestones: .NET 10 SR10, .NET 10 SR11 Aug 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-label Label, Span community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/windows s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

8 participants