Skip to content

Keep one DynamicResource registration per specificity - #38103

Closed
otretiak wants to merge 26 commits into
dotnet:mainfrom
otretiak:fix/dynamicresource-specificity-in-visualstate
Closed

otretiak wants to merge 26 commits into
dotnet:mainfrom
otretiak:fix/dynamicresource-specificity-in-visualstate

Conversation

@otretiak

@otretiak otretiak commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Description of Change

Element stored a single (key, specificity) pair per BindableProperty, so a
{DynamicResource}-valued Setter inside a VisualState overwrote the registration a style
had installed when the state was entered (OnSetDynamicResource replaces the entry when the
incoming specificity is greater or equal, and a full-VSM setter outranks a style's), and
Setter.UnApply then removed the entry outright when the state was left.

From that point Element.OnResourcesChanged never saw the property again: the element stopped
following the resource for the rest of its lifetime, back in the default state, with no way to
recover. A theme switch afterwards leaves it on whatever value happened to be resolved at the
moment the state was entered.

BindableObject.RemoveDynamicResource(BindableProperty, SetterSpecificity) already accepted a
specificity and discarded it, while its siblings RemoveBinding(property, specificity) and
ClearValue(property, specificity) honour theirs.

This stores the registrations in SetterSpecificityList<string> — the same structure Values and
Bindings already use — so each specificity keeps its own entry:

  • entering a state adds the state's registration without disturbing the style's;
  • leaving it removes only that one and republishes the next one down, so the property keeps
    tracking;
  • BindableContextAttributes.IsDynamicResource is cleared only once the last registration for the
    property is gone.

SetterSpecificityList<T> gains GetValueAt/GetSpecificityAt so Element can enumerate every
registered key (GetMergedResources needs all of them, not just the effective one).

Issues Fixed

Fixes #38069

Tests

DynamicResourceTests.VisualStateDynamicResourceDoesNotDestroyTheStylesRegistration walks the
full cycle on a Button whose style paints BackgroundColor from one dynamic resource and whose
Disabled state paints it from another: enabled colour, disabled colour, back to the enabled
colour, and then a change to the enabled resource must still reach the element.

Without the change the last assertion fails — Expected: Red, Actual: Blue, the element frozen on
the value resolved before the state was entered. The full Controls.Core.UnitTests suite passes
with it (5716 passed, 0 failed, 30 skipped).

Note on the target branch

Opened against release/10.0.1xx-sr10 rather than main, because the defect is present in
shipping .NET 10 (reproduced by the triage team on 10.0.0, 10.0.71, 10.0.90 and 10.0.100) and
this is the line those consumers update along.

The same change applies to main, with one adjustment: SetterSpecificityList<T> became a
struct there, so the entry has to be written back into the dictionary after mutation rather
than mutated in place through TryGetValue. Happy to open that PR as well, or to reorder these
two if you would rather take main first and service back.

kubaflo and others added 25 commits August 10, 2026 22:32
<!-- Please let the below note in for people that 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 if this change resolves your issue.
Thank you!

## Summary

Completes the SR10 servicing-version transition by using the `servicing`
prerelease label, removing the `inflight/current` override, and enabling
stable package versions.
…ed containers (dotnet#37312)

<!-- Please let the below note in for people that 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 if this change resolves your issue.
Thank you!

Backport of dotnet#37291 to `release/10.0.1xx-sr10`.

/cc @kubaflo

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…dotnet#37594)

Removes the repository-owned VG20 import and synchronizes the relevant
Arcade credential-removal changes on `release/10.0.1xx-sr10`.

Tracked by https://dev.azure.com/dnceng/internal/_workitems/edit/12131

Copilot-Session: e890b71a-c1aa-416c-a15c-be8da9fdd9b4
…7613)

### Description of Change

Backport of dotnet#37607 to `release/10.0.1xx-sr10`.

Replace MAUI's long-lived `dn-bot-ceapex-package-r` dependency with a
short-lived Entra token for OneLocBuild package restores. The pipeline
acquires the token through the existing DevDiv
`dnceng-onelocbuild-ceapex` workload-identity service connection and
Arcade's shared federated-token helper. GitHub PR authentication is
unchanged.

The DevDiv service connection is configured for workload identity
federation and MAUI pipeline 13330 is authorized to use it.

### Validation

- Parsed the updated pipeline as YAML.
- Verified the shared federated-token helper exists on this release
branch.
- Verified the legacy ceapex PAT is no longer referenced by MAUI's
repo-owned localization pipeline.

### Issues Fixed

Tracks [dnceng work item
10151](https://dev.azure.com/dnceng/internal/_workitems/edit/10151).

Copilot-Session: 80f6a0c6-7947-4200-bb78-7f0fc01d671a
…ies (dotnet#37724)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1e7f77e3-4862-4b92-a662-d12b5918bb59
…et#37725)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1e7f77e3-4862-4b92-a662-d12b5918bb59
)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1e7f77e3-4862-4b92-a662-d12b5918bb59
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1e7f77e3-4862-4b92-a662-d12b5918bb59
…7728)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1e7f77e3-4862-4b92-a662-d12b5918bb59
…7729)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1e7f77e3-4862-4b92-a662-d12b5918bb59
)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1e7f77e3-4862-4b92-a662-d12b5918bb59
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1e7f77e3-4862-4b92-a662-d12b5918bb59
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d00747b7-96f3-4e7a-8dfb-e3a48db04b2d
…#37542)

Backport the isolated four-file Shell payload from dotnet#37542 without its unrelated inflight branch history.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: d00747b7-96f3-4e7a-8dfb-e3a48db04b2d
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d00747b7-96f3-4e7a-8dfb-e3a48db04b2d
<!-- Please let the below note in for people that 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 if this change resolves your issue.
Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->


### Root cause
 
This PR addresses Android, iOS, and Mac Catalyst test failures.
 
#### Android
 
The MediaPicker tests searched for a specific Android Photo Picker
"Cancel" button using XPath. The system picker UI differs across Android
versions, causing the tests to time out.
 
#### Mac Catalyst
 
Issue36769 test fails because the OnAppearing code in CI runs before the
button is loaded in the UI.

### Description of Change
 
- Removed `WaitForPhotoPicker()` from the Android MediaPicker tests.
- Used `App.Back()` directly to close the picker before verifying
cancellation.
- Re-saved the expected iOS snapshots.
- Fixed test case failure in Issue36769 - Switched Issue36749 button
background verification from OnAppearing to the Button's Loaded event
for reliable pass/fail checks
 
### Tests
 
#### Android
 
- `OverlappingPhotoPickerRequestsAreRejected`
- `PickPhotosAsyncShouldReturnFromChildActivity`
 
#### iOS
 
- `ShellTabBarBackgroundColor`
- `MoreTabShouldRespectNavBarCustomization`
- `BottomTabColorTest`
 
#### Mac Catalyst
 
- `NativeStyledButtonPreservesInitialAndClearsDetachedBackground`
…otnet#37960)

### Issue Details
On Windows, dynamically updating the content of a ContentPresenter can
throw a System.ArgumentException when the content contains controls such
as RefreshView or ScrollView.
 
This happens when a platform view is reused while it is still attached
to its previous WinUI parent, causing a “PointerEventRouter object
already has an owner” exception.

The initial fix detached the platform view from its previous parent, but
some scenarios still failed because:
* The logical content was not detached before creating the
control-template platform tree.
* ContentPanel.Content = null could leave stale children in
CachedChildren.

### Description of Change

<!-- Enter description of the fix in this section -->
Updated the Windows ContentViewHandler content-update flow to properly
handle direct, templated, and empty content.
* Detach the existing content before creating the template platform
tree.
* Added a RemoveFromParent helper to safely detach the incoming platform
view without disconnecting its handler.
* Clear ContentPanel.CachedChildren before assigning new content or when
the content becomes null.

### 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 dotnet#37958 

Fixed below test cases:
Control.DeviceTests:
* ControlTemplateInitializesCorrectly 
* ControlTemplateCanBeReplacedCorrectly 
* ContentView updating it's ControlTemplate works 
* PropagateContextCorrectly

Core.DeviceTests:

* Content Initializes Correctly
* Content Updates Correctly
* ContentIsSetInitially
* WindowSupportsEmptyPage_Platform
This pull request makes a minor UI adjustment to the `Issue35826` test
case in the host app. The only change is to the padding of the
`pickerAvailabilityLabel`, increasing the top padding to improve visual
spacing.

* UI Adjustment:
* Increased the top padding of pickerAvailabilityLabel from 0 to 150 in
Issue35826.cs to prevent the label from being hidden behind the status
bar, which could cause a timeout exception during the test.

Removed the unnecessary changes added by Copilot that caused an
exception in the test, while retaining the original test and the fix
from dotnet#36769

**Fixes:** dotnet#37746

---------

Co-authored-by: devanathan-vaithiyanathan <114395405+devanathan-vaithiyanathan@users.noreply.github.com>
Backport of dotnet#37772.

(cherry picked from commit 9d587ce)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: b603f8b0-824a-48b4-92e5-c891584266bf
Backport of dotnet#37404 for dotnet#37361.

(cherry picked from commit 53ba0db)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: b603f8b0-824a-48b4-92e5-c891584266bf
Backport of dotnet#37680 for dotnet#37638.

(cherry picked from commit 1cdf1b6)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: b603f8b0-824a-48b4-92e5-c891584266bf
…load (dotnet#37746)

<!-- Please let the below note in for people that 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 if this change resolves your issue.
Thank you!

<!-- release-readiness-agent: human-approval-required -->
## Summary

Integrates the staged **.NET MAUI 10.0.101 (SR10.1)** payload from
`inflight/10.0.101` into `release/10.0.1xx-sr10`, based on the shipped
`10.0.100` release.

The full release inventory and servicing decisions are tracked in
dotnet#37723. The [authoritative regression
query](https://github.com/dotnet/maui/issues?q=repo%3Adotnet%2Fmaui%20is%3Aissue%20is%3Aopen%20%28label%3A%22regressed-in-10.0.10%22%20OR%20label%3A%22regressed-in-10.0.20%22%20OR%20label%3A%22regressed-in-10.0.30%22%20OR%20label%3A%22regressed-in-10.0.40%22%20OR%20label%3A%22regressed-in-10.0.50%22%20OR%20label%3A%22regressed-in-10.0.60%22%20OR%20label%3A%22regressed-in-10.0.70%22%20OR%20label%3A%22regressed-in-10.0.80%22%20OR%20label%3A%22regressed-in-10.0.90%22%20OR%20label%3A%22regressed-in-10.0.100%22%29)
remains the source for the servicing-regression scope.

> [!IMPORTANT]
> Checked items under **Staged in this PR** are merged into
`inflight/10.0.101`, not yet into `release/10.0.1xx-sr10`. They reach
the release branch only when this aggregate PR is merged.

## Status at a glance

- [x] Stage the selected regression backports independently on
`inflight/10.0.101`.
- [x] Stage the SkiaSharp 4.150.1 payload and selective
`SKPath.AddCircle` compatibility fix.
- [x] Stage the isolated iOS 26 Liquid Glass TabBar payload from dotnet#37542.
- [ ] Complete or explicitly defer the six unresolved servicing
regressions listed below.
- [ ] Complete the release gates and merge this PR into
`release/10.0.1xx-sr10`.

## Staged in this PR

### Servicing regressions

- [x] dotnet#35826 — Android MediaPicker completion from child activities.
Source dotnet#35944; component backport dotnet#37724.
- [x] dotnet#36298 — Windows dynamic `ContentPresenter` assignment. Source
dotnet#36430; component backport dotnet#37725.
- [x] dotnet#36749 — preserve custom iOS Button styling. Source dotnet#36769;
component backport dotnet#37726.
- [x] dotnet#36736 — align Android SwipeItem content. Source dotnet#36820; component
backport dotnet#37727.
- [x] dotnet#34563 — per-edge iOS safe-area handling. Source dotnet#37033; component
backport dotnet#37728.
- [x] dotnet#37706 — Android root-page back handling. Source dotnet#37709; component
backport dotnet#37729.
- [x] dotnet#37705 — Android Material 3 status-bar contrast. Source dotnet#37710;
component backport dotnet#37730.
- [x] dotnet#37423 — restore native iOS 26 Liquid Glass TabBar behavior
through the isolated four-file payload from merged PR dotnet#37542.
- [x] dotnet#37418 — Android off-screen `TranslationY` layout padding. Source
fix dotnet#37772; focused backport commit `10799e67df`.
- [x] dotnet#37361 — iOS RefreshView pull-to-refresh with an empty
CollectionView. Source fix dotnet#37404; focused backport commit `d26faa8e93`.
- [x] dotnet#37638 — Android `Screenshot.CaptureAsync` synchronous UI-thread
deadlock. Source fix dotnet#37680; focused backport commit `778040a233`.

### Planned Skia payload

- [x] Port the Skia/Svg.Skia update from dotnet#36255 through component
backport dotnet#37731.
- [x] Include only the required `SKPath.AddCircle` compatibility change
from dotnet#36787; exclude its unrelated SourceGen changes.
- [x] Confirm a matching SkiaSharp 4.150.1 native-assets/PDB build for
`_SkiaSharpNativeAssetsVersion`, or record an explicit release-owner
waiver.

### Integration follow-ups

- [x] Apply the aggregate review fixes for safe-area cache invalidation,
Activity-for-result cancellation ownership, and Android theme-test
semantics.
- [x] Keep the final branch payload as focused release commits without
unrelated `inflight/current` history.
- [x] Validate the dotnet#37418 and dotnet#37638 focused Android UI tests on the
aggregate branch (2/2 passed).
- [ ] Validate the dotnet#37361 focused iOS UI test on the aggregate branch.

## Already present on the SR10 base — no new merge needed

- [x] dotnet#36852 — Android Shell hidden-fragment leak; fix dotnet#36903 is already
in SR10.
- [x] dotnet#36735 — Android ActivityIndicator visibility; fix dotnet#36748 is
already in SR10.
- [x] dotnet#36853 — Android Shell DI-singleton route blank page; fix dotnet#36903
is already in SR10.
- [x] dotnet#36942 — Android UI event handling; fix dotnet#36988 is already in SR10.
- [x] dotnet#37281 — Android scrolling inside shadowed containers; backport
dotnet#37312 is already in SR10.

## Completed disposition — no backport required

- [x] dotnet#37700 — closed as intended SR10 `SwipeView.Threshold` behavior
from dotnet#36878; any SwipeItem sizing concern should be tracked separately.

## Not included yet — merge, defer, or explicitly disposition before
payload freeze

- [ ] dotnet#35301 — Windows CollectionView applies WinUI styling by default;
no linked fix PR.
- [ ] dotnet#34491 — Android CollectionView selection with
`PointerGestureRecognizer`; replacement fix dotnet#37952 remains draft against
`main`.
- [ ] dotnet#35059 — iOS app becomes unresponsive when opening a ComboBox
dropdown in landscape; no linked fix PR.
- [ ] dotnet#37407 — iOS TimePicker default `t` format forces en-US; fix
dotnet#37797 remains draft against `main`.
- [ ] dotnet#36269 — Android `SafeAreaEdges` with Shell tab navigation and
hidden TabBar; source fix dotnet#36474 remains open against `main` and has no
SR10 backport.
- [ ] dotnet#37657 — Android Shell/root-page `OnBackButtonPressed()` in
Release builds; no linked fix PR.

## Release completion

### Before merging this PR

- [ ] Refresh the authoritative query and reconcile dotnet#37723 with its
current results.
- [ ] Record an include/defer/close decision for every unresolved
regression above.
- [ ] Validate every included regression on its reported OS/version
using the `10.0.101` candidate packages.
- [ ] Complete current-head aggregate CI and resolve or explicitly waive
every required build/device/UI-test failure.
- [ ] Resolve or waive the Skia native-assets/PDB release gate.
- [ ] Bump `eng/Versions.props` from patch `100` to `101` after the
payload is frozen.
- [ ] Obtain the required independent current-head maintainer approvals.
- [ ] Merge dotnet#37746 into `release/10.0.1xx-sr10`.

### After merge

- [ ] Confirm BAR promotion and the per-build validation feed used by
the ship assessment.
- [ ] Publish and tag `10.0.101`.
- [ ] Complete the Visual Studio insertion/default-MAUI-version update.

## Notes

- No automated `/backport` command was used for this release payload.
- Supersedes dotnet#37745, which GitHub automatically closed when the
integration branch was renamed from `vs/10.0.101` to
`inflight/10.0.101`.
<!-- Please let the below note in for people that 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 if this change resolves your issue.
Thank you!

## Summary

Bumps the SR10 release branch package patch version from `10.0.100` to
`10.0.101` after the SR10.1 payload merge.

## Changes

- Updates `eng/Versions.props` `PatchVersion` from `100` to `101`.
- Leaves `SdkBandVersion`, `PreReleaseVersionLabel=servicing`, and
stable-package settings unchanged.

## Context

Follow-up to dotnet#37746 for the 10.0.101 release completion checklist.
<!-- Please let the below note in for people that 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 if this change resolves your issue.
Thank you!

## Description

Removes the empty Azure Pipelines conditional left in
`eng/pipelines/common/variables.yml` after dotnet#37594 removed the
`Publish-Build-Assets` variable group.

The dangling mapping prevents the official `dotnet-maui` pipeline from
compiling:

```text
/eng/pipelines/common/variables.yml (Line: 81, Col: 70): Expected a mapping
/eng/pipelines/common/variables.yml (Line: 81, Col: 7): Expected at least one key-value pair in the mapping
```

This blocked [official build
3063359](https://dev.azure.com/dnceng/internal/_build/results?buildId=3063359)
before any jobs ran, preventing creation and default-channel promotion
of the SR10.1 BAR build.

## Validation

- Parsed `eng/pipelines/common/variables.yml` successfully with Ruby
Psych.
- `git diff --check` passes.

After merge, rerun the `dotnet-maui` official pipeline for
`release/10.0.1xx-sr10`; its existing `.NET 10.0.1xx SDK`
default-channel mapping should create the per-build validation feed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b603f8b0-824a-48b4-92e5-c891584266bf
@github-actions

github-actions Bot commented Sep 2, 2026

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 -- 38103

Or

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

@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label Sep 2, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hey there @@otretiak! 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

Copy link
Copy Markdown
Contributor

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

@github-actions github-actions Bot added the area-controls-general General issues that span multiple controls, or common base classes such as View or Element label Sep 2, 2026
Element stored a single (key, specificity) pair per BindableProperty, so a
{DynamicResource}-valued setter in a VisualState overwrote the registration a
style had installed on entry, and Setter.UnApply removed the entry outright on
exit. From then on OnResourcesChanged never saw the property again: the element
stopped following the resource for the rest of its life, in the default state,
with no way to recover. A theme switch after that leaves the element on whatever
value happened to be resolved when the state was entered.

RemoveDynamicResource already accepted a SetterSpecificity and discarded it,
while its siblings RemoveBinding and ClearValue honour theirs.

Store the registrations in SetterSpecificityList<string> -- the same structure
Values and Bindings already use -- so each specificity keeps its own entry.
Leaving a state removes only that state's registration and republishes the next
one down; the flag on the property context is cleared only once the last
registration is gone.

Fixes dotnet#38069

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@otretiak
otretiak force-pushed the fix/dynamicresource-specificity-in-visualstate branch from aab2571 to 8cd5ccd Compare September 2, 2026 09:08
@otretiak
otretiak changed the base branch from main to release/10.0.1xx-sr10 September 2, 2026 09:09
@kubaflo
kubaflo changed the base branch from release/10.0.1xx-sr10 to main September 2, 2026 14:09

@kubaflo kubaflo 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.

Cold you please create a new one that targets main?

@otretiak

otretiak commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks — done, #38152 targets main.

It was not a straight retarget: SetterSpecificityList<T> is a struct on main with the
_top/_second/_rest layout, so the mutated copy now has to be written back into the
dictionary, and the accessors Element needs to enumerate every registered key walk those three
levels instead of indexing an array. Verified against the provisioned .NET 11 SDK —
Controls.Core.UnitTests passes, and the new test fails without the change.

Happy to open a backport to release/10.0.1xx-sr10 once main is in, if you want it there: the
defect ships in .NET 10 today (your team reproduced it on 10.0.0 through 10.0.100 in #38069), and
the servicing branch still has the class-based list, so that version of the patch is simply the
same change without the write-back.

kubaflo added a commit that referenced this pull request Sep 4, 2026
### Description of Change

Reopened against `main` as requested in #38103.

`Element` stored a single `(key, specificity)` pair per
`BindableProperty`, so a
`{DynamicResource}`-valued `Setter` inside a `VisualState` **overwrote**
the registration a style
had installed when the state was entered (`OnSetDynamicResource`
replaces the entry when the
incoming specificity is greater or equal, and a full-VSM setter outranks
a style's), and
`Setter.UnApply` then removed the entry outright when the state was
left.

From that point `Element.OnResourcesChanged` never saw the property
again: the element stopped
following the resource for the rest of its lifetime, back in the default
state, with no way to
recover. A theme switch afterwards leaves it on whatever value happened
to be resolved at the
moment the state was entered.

`BindableObject.RemoveDynamicResource(BindableProperty,
SetterSpecificity)` already accepted a
specificity and discarded it, while its siblings
`RemoveBinding(property, specificity)` and
`ClearValue(property, specificity)` honour theirs.

This stores the registrations in `SetterSpecificityList<string>` — the
same structure `Values` and
`Bindings` already use — so each specificity keeps its own entry:

- entering a state adds the state's registration without disturbing the
style's;
- leaving it removes only that one and republishes the next one down, so
the property keeps
  tracking;
- `BindableContextAttributes.IsDynamicResource` is cleared only once the
last registration for the
  property is gone.

`SetterSpecificityList<T>` also gains `GetValueAt`/`GetSpecificityAt`,
because `Element` has to
enumerate every registered key, not just the effective one —
`GetMergedResources` and both
`OnResourcesChanged` overloads need all of them.

### Issues Fixed

Fixes #38069

### Tests


`DynamicResourceTests.VisualStateDynamicResourceDoesNotDestroyTheStylesRegistration`
walks the full
cycle on a `Button` whose style paints `BackgroundColor` from one
dynamic resource and whose
`Disabled` state paints it from another: enabled colour, disabled
colour, back to the enabled
colour, and then a change to the enabled resource must still reach the
element.

Without the change that last assertion fails — `Expected: Red, Actual:
Blue`, the element frozen on
the value resolved before the state was entered (verified by reverting
only the three product files
to `main` and re-running the test).

`Controls.Core.UnitTests` on this branch: **5645 passed, 30 skipped, 0
failed**.

The same change was verified against `release/10.0.1xx-sr10` in #38103
(5716 passed, 0 failed); the
two branches now carry the identical patch.

### Note on the force-push

This branch was originally written against `main` while it still carried
the accidental `net11.0`
payload from #37995, where `SetterSpecificityList<T>` is a struct.
#38155 reverted that payload, so
the branch has been rebuilt on top of current `main` (`c478f6b4`) with
the class-based version of
the patch — the same one that was validated on `release/10.0.1xx-sr10`.

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Sep 6, 2026
### Description of Change

Reopened against `main` as requested in #38103.

`Element` stored a single `(key, specificity)` pair per
`BindableProperty`, so a
`{DynamicResource}`-valued `Setter` inside a `VisualState` **overwrote**
the registration a style
had installed when the state was entered (`OnSetDynamicResource`
replaces the entry when the
incoming specificity is greater or equal, and a full-VSM setter outranks
a style's), and
`Setter.UnApply` then removed the entry outright when the state was
left.

From that point `Element.OnResourcesChanged` never saw the property
again: the element stopped
following the resource for the rest of its lifetime, back in the default
state, with no way to
recover. A theme switch afterwards leaves it on whatever value happened
to be resolved at the
moment the state was entered.

`BindableObject.RemoveDynamicResource(BindableProperty,
SetterSpecificity)` already accepted a
specificity and discarded it, while its siblings
`RemoveBinding(property, specificity)` and
`ClearValue(property, specificity)` honour theirs.

This stores the registrations in `SetterSpecificityList<string>` — the
same structure `Values` and
`Bindings` already use — so each specificity keeps its own entry:

- entering a state adds the state's registration without disturbing the
style's;
- leaving it removes only that one and republishes the next one down, so
the property keeps
  tracking;
- `BindableContextAttributes.IsDynamicResource` is cleared only once the
last registration for the
  property is gone.

`SetterSpecificityList<T>` also gains `GetValueAt`/`GetSpecificityAt`,
because `Element` has to
enumerate every registered key, not just the effective one —
`GetMergedResources` and both
`OnResourcesChanged` overloads need all of them.

### Issues Fixed

Fixes #38069

### Tests


`DynamicResourceTests.VisualStateDynamicResourceDoesNotDestroyTheStylesRegistration`
walks the full
cycle on a `Button` whose style paints `BackgroundColor` from one
dynamic resource and whose
`Disabled` state paints it from another: enabled colour, disabled
colour, back to the enabled
colour, and then a change to the enabled resource must still reach the
element.

Without the change that last assertion fails — `Expected: Red, Actual:
Blue`, the element frozen on
the value resolved before the state was entered (verified by reverting
only the three product files
to `main` and re-running the test).

`Controls.Core.UnitTests` on this branch: **5645 passed, 30 skipped, 0
failed**.

The same change was verified against `release/10.0.1xx-sr10` in #38103
(5716 passed, 0 failed); the
two branches now carry the identical patch.

### Note on the force-push

This branch was originally written against `main` while it still carried
the accidental `net11.0`
payload from #37995, where `SetterSpecificityList<T>` is a struct.
#38155 reverted that payload, so
the branch has been rebuilt on top of current `main` (`c478f6b4`) with
the class-based version of
the patch — the same one that was validated on `release/10.0.1xx-sr10`.

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Sep 7, 2026
### Description of Change

Reopened against `main` as requested in #38103.

`Element` stored a single `(key, specificity)` pair per
`BindableProperty`, so a
`{DynamicResource}`-valued `Setter` inside a `VisualState` **overwrote**
the registration a style
had installed when the state was entered (`OnSetDynamicResource`
replaces the entry when the
incoming specificity is greater or equal, and a full-VSM setter outranks
a style's), and
`Setter.UnApply` then removed the entry outright when the state was
left.

From that point `Element.OnResourcesChanged` never saw the property
again: the element stopped
following the resource for the rest of its lifetime, back in the default
state, with no way to
recover. A theme switch afterwards leaves it on whatever value happened
to be resolved at the
moment the state was entered.

`BindableObject.RemoveDynamicResource(BindableProperty,
SetterSpecificity)` already accepted a
specificity and discarded it, while its siblings
`RemoveBinding(property, specificity)` and
`ClearValue(property, specificity)` honour theirs.

This stores the registrations in `SetterSpecificityList<string>` — the
same structure `Values` and
`Bindings` already use — so each specificity keeps its own entry:

- entering a state adds the state's registration without disturbing the
style's;
- leaving it removes only that one and republishes the next one down, so
the property keeps
  tracking;
- `BindableContextAttributes.IsDynamicResource` is cleared only once the
last registration for the
  property is gone.

`SetterSpecificityList<T>` also gains `GetValueAt`/`GetSpecificityAt`,
because `Element` has to
enumerate every registered key, not just the effective one —
`GetMergedResources` and both
`OnResourcesChanged` overloads need all of them.

### Issues Fixed

Fixes #38069

### Tests


`DynamicResourceTests.VisualStateDynamicResourceDoesNotDestroyTheStylesRegistration`
walks the full
cycle on a `Button` whose style paints `BackgroundColor` from one
dynamic resource and whose
`Disabled` state paints it from another: enabled colour, disabled
colour, back to the enabled
colour, and then a change to the enabled resource must still reach the
element.

Without the change that last assertion fails — `Expected: Red, Actual:
Blue`, the element frozen on
the value resolved before the state was entered (verified by reverting
only the three product files
to `main` and re-running the test).

`Controls.Core.UnitTests` on this branch: **5645 passed, 30 skipped, 0
failed**.

The same change was verified against `release/10.0.1xx-sr10` in #38103
(5716 passed, 0 failed); the
two branches now carry the identical patch.

### Note on the force-push

This branch was originally written against `main` while it still carried
the accidental `net11.0`
payload from #37995, where `SetterSpecificityList<T>` is a struct.
#38155 reverted that payload, so
the branch has been rebuilt on top of current `main` (`c478f6b4`) with
the class-based version of
the patch — the same one that was validated on `release/10.0.1xx-sr10`.

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Sep 8, 2026
### Description of Change

Reopened against `main` as requested in #38103.

`Element` stored a single `(key, specificity)` pair per
`BindableProperty`, so a
`{DynamicResource}`-valued `Setter` inside a `VisualState` **overwrote**
the registration a style
had installed when the state was entered (`OnSetDynamicResource`
replaces the entry when the
incoming specificity is greater or equal, and a full-VSM setter outranks
a style's), and
`Setter.UnApply` then removed the entry outright when the state was
left.

From that point `Element.OnResourcesChanged` never saw the property
again: the element stopped
following the resource for the rest of its lifetime, back in the default
state, with no way to
recover. A theme switch afterwards leaves it on whatever value happened
to be resolved at the
moment the state was entered.

`BindableObject.RemoveDynamicResource(BindableProperty,
SetterSpecificity)` already accepted a
specificity and discarded it, while its siblings
`RemoveBinding(property, specificity)` and
`ClearValue(property, specificity)` honour theirs.

This stores the registrations in `SetterSpecificityList<string>` — the
same structure `Values` and
`Bindings` already use — so each specificity keeps its own entry:

- entering a state adds the state's registration without disturbing the
style's;
- leaving it removes only that one and republishes the next one down, so
the property keeps
  tracking;
- `BindableContextAttributes.IsDynamicResource` is cleared only once the
last registration for the
  property is gone.

`SetterSpecificityList<T>` also gains `GetValueAt`/`GetSpecificityAt`,
because `Element` has to
enumerate every registered key, not just the effective one —
`GetMergedResources` and both
`OnResourcesChanged` overloads need all of them.

### Issues Fixed

Fixes #38069

### Tests


`DynamicResourceTests.VisualStateDynamicResourceDoesNotDestroyTheStylesRegistration`
walks the full
cycle on a `Button` whose style paints `BackgroundColor` from one
dynamic resource and whose
`Disabled` state paints it from another: enabled colour, disabled
colour, back to the enabled
colour, and then a change to the enabled resource must still reach the
element.

Without the change that last assertion fails — `Expected: Red, Actual:
Blue`, the element frozen on
the value resolved before the state was entered (verified by reverting
only the three product files
to `main` and re-running the test).

`Controls.Core.UnitTests` on this branch: **5645 passed, 30 skipped, 0
failed**.

The same change was verified against `release/10.0.1xx-sr10` in #38103
(5716 passed, 0 failed); the
two branches now carry the identical patch.

### Note on the force-push

This branch was originally written against `main` while it still carried
the accidental `net11.0`
payload from #37995, where `SetterSpecificityList<T>` is a struct.
#38155 reverted that payload, so
the branch has been rebuilt on top of current `main` (`c478f6b4`) with
the class-based version of
the patch — the same one that was validated on `release/10.0.1xx-sr10`.

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Sep 9, 2026
### Description of Change

Reopened against `main` as requested in #38103.

`Element` stored a single `(key, specificity)` pair per
`BindableProperty`, so a
`{DynamicResource}`-valued `Setter` inside a `VisualState` **overwrote**
the registration a style
had installed when the state was entered (`OnSetDynamicResource`
replaces the entry when the
incoming specificity is greater or equal, and a full-VSM setter outranks
a style's), and
`Setter.UnApply` then removed the entry outright when the state was
left.

From that point `Element.OnResourcesChanged` never saw the property
again: the element stopped
following the resource for the rest of its lifetime, back in the default
state, with no way to
recover. A theme switch afterwards leaves it on whatever value happened
to be resolved at the
moment the state was entered.

`BindableObject.RemoveDynamicResource(BindableProperty,
SetterSpecificity)` already accepted a
specificity and discarded it, while its siblings
`RemoveBinding(property, specificity)` and
`ClearValue(property, specificity)` honour theirs.

This stores the registrations in `SetterSpecificityList<string>` — the
same structure `Values` and
`Bindings` already use — so each specificity keeps its own entry:

- entering a state adds the state's registration without disturbing the
style's;
- leaving it removes only that one and republishes the next one down, so
the property keeps
  tracking;
- `BindableContextAttributes.IsDynamicResource` is cleared only once the
last registration for the
  property is gone.

`SetterSpecificityList<T>` also gains `GetValueAt`/`GetSpecificityAt`,
because `Element` has to
enumerate every registered key, not just the effective one —
`GetMergedResources` and both
`OnResourcesChanged` overloads need all of them.

### Issues Fixed

Fixes #38069

### Tests


`DynamicResourceTests.VisualStateDynamicResourceDoesNotDestroyTheStylesRegistration`
walks the full
cycle on a `Button` whose style paints `BackgroundColor` from one
dynamic resource and whose
`Disabled` state paints it from another: enabled colour, disabled
colour, back to the enabled
colour, and then a change to the enabled resource must still reach the
element.

Without the change that last assertion fails — `Expected: Red, Actual:
Blue`, the element frozen on
the value resolved before the state was entered (verified by reverting
only the three product files
to `main` and re-running the test).

`Controls.Core.UnitTests` on this branch: **5645 passed, 30 skipped, 0
failed**.

The same change was verified against `release/10.0.1xx-sr10` in #38103
(5716 passed, 0 failed); the
two branches now carry the identical patch.

### Note on the force-push

This branch was originally written against `main` while it still carried
the accidental `net11.0`
payload from #37995, where `SetterSpecificityList<T>` is a struct.
#38155 reverted that payload, so
the branch has been rebuilt on top of current `main` (`c478f6b4`) with
the class-based version of
the patch — the same one that was validated on `release/10.0.1xx-sr10`.

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Sep 11, 2026
### Description of Change

Reopened against `main` as requested in #38103.

`Element` stored a single `(key, specificity)` pair per
`BindableProperty`, so a
`{DynamicResource}`-valued `Setter` inside a `VisualState` **overwrote**
the registration a style
had installed when the state was entered (`OnSetDynamicResource`
replaces the entry when the
incoming specificity is greater or equal, and a full-VSM setter outranks
a style's), and
`Setter.UnApply` then removed the entry outright when the state was
left.

From that point `Element.OnResourcesChanged` never saw the property
again: the element stopped
following the resource for the rest of its lifetime, back in the default
state, with no way to
recover. A theme switch afterwards leaves it on whatever value happened
to be resolved at the
moment the state was entered.

`BindableObject.RemoveDynamicResource(BindableProperty,
SetterSpecificity)` already accepted a
specificity and discarded it, while its siblings
`RemoveBinding(property, specificity)` and
`ClearValue(property, specificity)` honour theirs.

This stores the registrations in `SetterSpecificityList<string>` — the
same structure `Values` and
`Bindings` already use — so each specificity keeps its own entry:

- entering a state adds the state's registration without disturbing the
style's;
- leaving it removes only that one and republishes the next one down, so
the property keeps
  tracking;
- `BindableContextAttributes.IsDynamicResource` is cleared only once the
last registration for the
  property is gone.

`SetterSpecificityList<T>` also gains `GetValueAt`/`GetSpecificityAt`,
because `Element` has to
enumerate every registered key, not just the effective one —
`GetMergedResources` and both
`OnResourcesChanged` overloads need all of them.

### Issues Fixed

Fixes #38069

### Tests


`DynamicResourceTests.VisualStateDynamicResourceDoesNotDestroyTheStylesRegistration`
walks the full
cycle on a `Button` whose style paints `BackgroundColor` from one
dynamic resource and whose
`Disabled` state paints it from another: enabled colour, disabled
colour, back to the enabled
colour, and then a change to the enabled resource must still reach the
element.

Without the change that last assertion fails — `Expected: Red, Actual:
Blue`, the element frozen on
the value resolved before the state was entered (verified by reverting
only the three product files
to `main` and re-running the test).

`Controls.Core.UnitTests` on this branch: **5645 passed, 30 skipped, 0
failed**.

The same change was verified against `release/10.0.1xx-sr10` in #38103
(5716 passed, 0 failed); the
two branches now carry the identical patch.

### Note on the force-push

This branch was originally written against `main` while it still carried
the accidental `net11.0`
payload from #37995, where `SetterSpecificityList<T>` is a struct.
#38155 reverted that payload, so
the branch has been rebuilt on top of current `main` (`c478f6b4`) with
the class-based version of
the patch — the same one that was validated on `release/10.0.1xx-sr10`.

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Sep 15, 2026
### Description of Change

Reopened against `main` as requested in #38103.

`Element` stored a single `(key, specificity)` pair per
`BindableProperty`, so a
`{DynamicResource}`-valued `Setter` inside a `VisualState` **overwrote**
the registration a style
had installed when the state was entered (`OnSetDynamicResource`
replaces the entry when the
incoming specificity is greater or equal, and a full-VSM setter outranks
a style's), and
`Setter.UnApply` then removed the entry outright when the state was
left.

From that point `Element.OnResourcesChanged` never saw the property
again: the element stopped
following the resource for the rest of its lifetime, back in the default
state, with no way to
recover. A theme switch afterwards leaves it on whatever value happened
to be resolved at the
moment the state was entered.

`BindableObject.RemoveDynamicResource(BindableProperty,
SetterSpecificity)` already accepted a
specificity and discarded it, while its siblings
`RemoveBinding(property, specificity)` and
`ClearValue(property, specificity)` honour theirs.

This stores the registrations in `SetterSpecificityList<string>` — the
same structure `Values` and
`Bindings` already use — so each specificity keeps its own entry:

- entering a state adds the state's registration without disturbing the
style's;
- leaving it removes only that one and republishes the next one down, so
the property keeps
  tracking;
- `BindableContextAttributes.IsDynamicResource` is cleared only once the
last registration for the
  property is gone.

`SetterSpecificityList<T>` also gains `GetValueAt`/`GetSpecificityAt`,
because `Element` has to
enumerate every registered key, not just the effective one —
`GetMergedResources` and both
`OnResourcesChanged` overloads need all of them.

### Issues Fixed

Fixes #38069

### Tests


`DynamicResourceTests.VisualStateDynamicResourceDoesNotDestroyTheStylesRegistration`
walks the full
cycle on a `Button` whose style paints `BackgroundColor` from one
dynamic resource and whose
`Disabled` state paints it from another: enabled colour, disabled
colour, back to the enabled
colour, and then a change to the enabled resource must still reach the
element.

Without the change that last assertion fails — `Expected: Red, Actual:
Blue`, the element frozen on
the value resolved before the state was entered (verified by reverting
only the three product files
to `main` and re-running the test).

`Controls.Core.UnitTests` on this branch: **5645 passed, 30 skipped, 0
failed**.

The same change was verified against `release/10.0.1xx-sr10` in #38103
(5716 passed, 0 failed); the
two branches now carry the identical patch.

### Note on the force-push

This branch was originally written against `main` while it still carried
the accidental `net11.0`
payload from #37995, where `SetterSpecificityList<T>` is a struct.
#38155 reverted that payload, so
the branch has been rebuilt on top of current `main` (`c478f6b4`) with
the class-based version of
the patch — the same one that was validated on `release/10.0.1xx-sr10`.

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Sep 18, 2026
### Description of Change

Reopened against `main` as requested in #38103.

`Element` stored a single `(key, specificity)` pair per
`BindableProperty`, so a
`{DynamicResource}`-valued `Setter` inside a `VisualState` **overwrote**
the registration a style
had installed when the state was entered (`OnSetDynamicResource`
replaces the entry when the
incoming specificity is greater or equal, and a full-VSM setter outranks
a style's), and
`Setter.UnApply` then removed the entry outright when the state was
left.

From that point `Element.OnResourcesChanged` never saw the property
again: the element stopped
following the resource for the rest of its lifetime, back in the default
state, with no way to
recover. A theme switch afterwards leaves it on whatever value happened
to be resolved at the
moment the state was entered.

`BindableObject.RemoveDynamicResource(BindableProperty,
SetterSpecificity)` already accepted a
specificity and discarded it, while its siblings
`RemoveBinding(property, specificity)` and
`ClearValue(property, specificity)` honour theirs.

This stores the registrations in `SetterSpecificityList<string>` — the
same structure `Values` and
`Bindings` already use — so each specificity keeps its own entry:

- entering a state adds the state's registration without disturbing the
style's;
- leaving it removes only that one and republishes the next one down, so
the property keeps
  tracking;
- `BindableContextAttributes.IsDynamicResource` is cleared only once the
last registration for the
  property is gone.

`SetterSpecificityList<T>` also gains `GetValueAt`/`GetSpecificityAt`,
because `Element` has to
enumerate every registered key, not just the effective one —
`GetMergedResources` and both
`OnResourcesChanged` overloads need all of them.

### Issues Fixed

Fixes #38069

### Tests


`DynamicResourceTests.VisualStateDynamicResourceDoesNotDestroyTheStylesRegistration`
walks the full
cycle on a `Button` whose style paints `BackgroundColor` from one
dynamic resource and whose
`Disabled` state paints it from another: enabled colour, disabled
colour, back to the enabled
colour, and then a change to the enabled resource must still reach the
element.

Without the change that last assertion fails — `Expected: Red, Actual:
Blue`, the element frozen on
the value resolved before the state was entered (verified by reverting
only the three product files
to `main` and re-running the test).

`Controls.Core.UnitTests` on this branch: **5645 passed, 30 skipped, 0
failed**.

The same change was verified against `release/10.0.1xx-sr10` in #38103
(5716 passed, 0 failed); the
two branches now carry the identical patch.

### Note on the force-push

This branch was originally written against `main` while it still carried
the accidental `net11.0`
payload from #37995, where `SetterSpecificityList<T>` is a struct.
#38155 reverted that payload, so
the branch has been rebuilt on top of current `main` (`c478f6b4`) with
the class-based version of
the patch — the same one that was validated on `release/10.0.1xx-sr10`.

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Sep 21, 2026
### Description of Change

Reopened against `main` as requested in #38103.

`Element` stored a single `(key, specificity)` pair per
`BindableProperty`, so a
`{DynamicResource}`-valued `Setter` inside a `VisualState` **overwrote**
the registration a style
had installed when the state was entered (`OnSetDynamicResource`
replaces the entry when the
incoming specificity is greater or equal, and a full-VSM setter outranks
a style's), and
`Setter.UnApply` then removed the entry outright when the state was
left.

From that point `Element.OnResourcesChanged` never saw the property
again: the element stopped
following the resource for the rest of its lifetime, back in the default
state, with no way to
recover. A theme switch afterwards leaves it on whatever value happened
to be resolved at the
moment the state was entered.

`BindableObject.RemoveDynamicResource(BindableProperty,
SetterSpecificity)` already accepted a
specificity and discarded it, while its siblings
`RemoveBinding(property, specificity)` and
`ClearValue(property, specificity)` honour theirs.

This stores the registrations in `SetterSpecificityList<string>` — the
same structure `Values` and
`Bindings` already use — so each specificity keeps its own entry:

- entering a state adds the state's registration without disturbing the
style's;
- leaving it removes only that one and republishes the next one down, so
the property keeps
  tracking;
- `BindableContextAttributes.IsDynamicResource` is cleared only once the
last registration for the
  property is gone.

`SetterSpecificityList<T>` also gains `GetValueAt`/`GetSpecificityAt`,
because `Element` has to
enumerate every registered key, not just the effective one —
`GetMergedResources` and both
`OnResourcesChanged` overloads need all of them.

### Issues Fixed

Fixes #38069

### Tests


`DynamicResourceTests.VisualStateDynamicResourceDoesNotDestroyTheStylesRegistration`
walks the full
cycle on a `Button` whose style paints `BackgroundColor` from one
dynamic resource and whose
`Disabled` state paints it from another: enabled colour, disabled
colour, back to the enabled
colour, and then a change to the enabled resource must still reach the
element.

Without the change that last assertion fails — `Expected: Red, Actual:
Blue`, the element frozen on
the value resolved before the state was entered (verified by reverting
only the three product files
to `main` and re-running the test).

`Controls.Core.UnitTests` on this branch: **5645 passed, 30 skipped, 0
failed**.

The same change was verified against `release/10.0.1xx-sr10` in #38103
(5716 passed, 0 failed); the
two branches now carry the identical patch.

### Note on the force-push

This branch was originally written against `main` while it still carried
the accidental `net11.0`
payload from #37995, where `SetterSpecificityList<T>` is a struct.
#38155 reverted that payload, so
the branch has been rebuilt on top of current `main` (`c478f6b4`) with
the class-based version of
the patch — the same one that was validated on `release/10.0.1xx-sr10`.

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Sep 27, 2026
### Description of Change

Reopened against `main` as requested in #38103.

`Element` stored a single `(key, specificity)` pair per
`BindableProperty`, so a
`{DynamicResource}`-valued `Setter` inside a `VisualState` **overwrote**
the registration a style
had installed when the state was entered (`OnSetDynamicResource`
replaces the entry when the
incoming specificity is greater or equal, and a full-VSM setter outranks
a style's), and
`Setter.UnApply` then removed the entry outright when the state was
left.

From that point `Element.OnResourcesChanged` never saw the property
again: the element stopped
following the resource for the rest of its lifetime, back in the default
state, with no way to
recover. A theme switch afterwards leaves it on whatever value happened
to be resolved at the
moment the state was entered.

`BindableObject.RemoveDynamicResource(BindableProperty,
SetterSpecificity)` already accepted a
specificity and discarded it, while its siblings
`RemoveBinding(property, specificity)` and
`ClearValue(property, specificity)` honour theirs.

This stores the registrations in `SetterSpecificityList<string>` — the
same structure `Values` and
`Bindings` already use — so each specificity keeps its own entry:

- entering a state adds the state's registration without disturbing the
style's;
- leaving it removes only that one and republishes the next one down, so
the property keeps
  tracking;
- `BindableContextAttributes.IsDynamicResource` is cleared only once the
last registration for the
  property is gone.

`SetterSpecificityList<T>` also gains `GetValueAt`/`GetSpecificityAt`,
because `Element` has to
enumerate every registered key, not just the effective one —
`GetMergedResources` and both
`OnResourcesChanged` overloads need all of them.

### Issues Fixed

Fixes #38069

### Tests


`DynamicResourceTests.VisualStateDynamicResourceDoesNotDestroyTheStylesRegistration`
walks the full
cycle on a `Button` whose style paints `BackgroundColor` from one
dynamic resource and whose
`Disabled` state paints it from another: enabled colour, disabled
colour, back to the enabled
colour, and then a change to the enabled resource must still reach the
element.

Without the change that last assertion fails — `Expected: Red, Actual:
Blue`, the element frozen on
the value resolved before the state was entered (verified by reverting
only the three product files
to `main` and re-running the test).

`Controls.Core.UnitTests` on this branch: **5645 passed, 30 skipped, 0
failed**.

The same change was verified against `release/10.0.1xx-sr10` in #38103
(5716 passed, 0 failed); the
two branches now carry the identical patch.

### Note on the force-push

This branch was originally written against `main` while it still carried
the accidental `net11.0`
payload from #37995, where `SetterSpecificityList<T>` is a struct.
#38155 reverted that payload, so
the branch has been rebuilt on top of current `main` (`c478f6b4`) with
the class-based version of
the patch — the same one that was validated on `release/10.0.1xx-sr10`.

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo added a commit that referenced this pull request Sep 27, 2026
### Description of Change

Reopened against `main` as requested in #38103.

`Element` stored a single `(key, specificity)` pair per
`BindableProperty`, so a
`{DynamicResource}`-valued `Setter` inside a `VisualState` **overwrote**
the registration a style
had installed when the state was entered (`OnSetDynamicResource`
replaces the entry when the
incoming specificity is greater or equal, and a full-VSM setter outranks
a style's), and
`Setter.UnApply` then removed the entry outright when the state was
left.

From that point `Element.OnResourcesChanged` never saw the property
again: the element stopped
following the resource for the rest of its lifetime, back in the default
state, with no way to
recover. A theme switch afterwards leaves it on whatever value happened
to be resolved at the
moment the state was entered.

`BindableObject.RemoveDynamicResource(BindableProperty,
SetterSpecificity)` already accepted a
specificity and discarded it, while its siblings
`RemoveBinding(property, specificity)` and
`ClearValue(property, specificity)` honour theirs.

This stores the registrations in `SetterSpecificityList<string>` — the
same structure `Values` and
`Bindings` already use — so each specificity keeps its own entry:

- entering a state adds the state's registration without disturbing the
style's;
- leaving it removes only that one and republishes the next one down, so
the property keeps
  tracking;
- `BindableContextAttributes.IsDynamicResource` is cleared only once the
last registration for the
  property is gone.

`SetterSpecificityList<T>` also gains `GetValueAt`/`GetSpecificityAt`,
because `Element` has to
enumerate every registered key, not just the effective one —
`GetMergedResources` and both
`OnResourcesChanged` overloads need all of them.

### Issues Fixed

Fixes #38069

### Tests


`DynamicResourceTests.VisualStateDynamicResourceDoesNotDestroyTheStylesRegistration`
walks the full
cycle on a `Button` whose style paints `BackgroundColor` from one
dynamic resource and whose
`Disabled` state paints it from another: enabled colour, disabled
colour, back to the enabled
colour, and then a change to the enabled resource must still reach the
element.

Without the change that last assertion fails — `Expected: Red, Actual:
Blue`, the element frozen on
the value resolved before the state was entered (verified by reverting
only the three product files
to `main` and re-running the test).

`Controls.Core.UnitTests` on this branch: **5645 passed, 30 skipped, 0
failed**.

The same change was verified against `release/10.0.1xx-sr10` in #38103
(5716 passed, 0 failed); the
two branches now carry the identical patch.

### Note on the force-push

This branch was originally written against `main` while it still carried
the accidental `net11.0`
payload from #37995, where `SetterSpecificityList<T>` is a struct.
#38155 reverted that payload, so
the branch has been rebuilt on top of current `main` (`c478f6b4`) with
the class-based version of
the patch — the same one that was validated on `release/10.0.1xx-sr10`.

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-general General issues that span multiple controls, or common base classes such as View or Element community ✨ Community Contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A {DynamicResource}-valued Setter in a VisualState permanently destroys the property's dynamic-resource registration

7 participants