Repository navigation
[Controls] Don't let Application resources override MainPage's own resources - #40325
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 40325Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 40325" |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
/rebase |
…sources Application.MainPage pushed the app's merged resources with OnResourcesChanged, bypassing the 'own keys win' filter in OnParentResourcesChanged. A page-level implicit style was then replaced by the Application-level one (regressed in 9.0 by #21879). Related to #20679. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
8a264a9 to
8ee6fa7
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
PR Test Gate
🧪 Gate analysis — click to expand⚠ Inconclusive. Setup, build, or execution did not produce a conclusive result. This does not prove the fix is incorrect. No interpretable test-group summary was produced. No additional test execution is inferred. Setup did not capture a verified PR head; no commit is claimed as tested. No immutable without-fix baseline was prepared. |
This comment has been minimized.
This comment has been minimized.
PR Test Gate
🧪 Gate analysis — click to expand⚠ Inconclusive. Setup, build, or execution did not produce a conclusive result. This does not prove the fix is incorrect. No interpretable test-group summary was produced. No additional test execution is inferred. Setup did not capture a verified PR head; no commit is claimed as tested. No immutable without-fix baseline was prepared. |
| var button = new Button(); | ||
| var page = new ContentPage | ||
| { | ||
| Resources = new ResourceDictionary |
There was a problem hiding this comment.
[moderate] Regression Prevention and Test Coverage - Add the same precedence case with the page's implicit Button style in Resources.MergedDictionaries. That variant still loses the red border and receives the application's blue background when assigned to MainPage: ResourceDictionary.Count excludes merged dictionaries, so VisualElement.OnParentResourcesChanged takes its empty-resource fallback and forwards the application style unfiltered. Adding an unrelated direct resource does not help because Resources.Keys also excludes merged dictionaries. The direct-entry-only fixture misses this remaining instance of the bug; cover the merged-dictionary variant and include its keys in the precedence filter without resolving unused lazy values.
…sources (#40325) <!-- 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! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). For .NET 11 fixes, only a maintainer retargets the approved PR to the active inflight lane and merges it after CI validates that final base. Do not merge individual fixes directly into `net11`; agents must not retarget or merge. ### Description of Change Setting `Application.MainPage` to a page that has its own implicit style let the Application's implicit style for the same type override the page's style. **Root cause:** since #21879 (9.0), the `MainPage` setter pushes the app's merged resources with `value.OnResourcesChanged(...)`. That skips the "own keys win" filter in `VisualElement.OnParentResourcesChanged`. As a result, keys that the page defines itself, such as the implicit-style key `Microsoft.Maui.Controls.Button`, were overwritten by the Application's values. **Fix:** call `value.OnParentResourcesChanged(...)` instead. The Application's resources still reach the page, including theme propagation from #21879, but the page's own keys take precedence again. This is the same path `Element.Parent` uses. Reproduced with the 9.0.120 and 10.0.41 packages. 7.0.101 and 8.0.3 behave correctly. **Tests** - New `StyleTests.PageImplicitStyleWinsOverApplicationImplicitStyleWhenSetAsMainPage`: fails without the fix and passes with it. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter "FullyQualifiedName~Maui21774|FullyQualifiedName~Maui16538|FullyQualifiedName~AppTheme|FullyQualifiedName~DynamicResource|FullyQualifiedName~Style"`: passed (190/190). - `dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj`: 6734 passed and 1 failed. The failure, `TwoWayBindingToNullableDoublePropertyWithEmptyStringBecomesNull`, also fails on `net11` without this change. - `CorrectDefaultRadioButtonThemeColorsInLightAndDarkModes` fails in a filtered 150-test run with or without the fix. It passes in a smaller AppTheme-only run, so it depends on test order. ### Issues Fixed Relates to #20679. This fixes the 9.0 page-versus-Application precedence regression found while investigating that issue. The scenario in #20679 itself is by design: implicit styles from different resource levels don't merge, and `CanCascade` doesn't change that. The workaround is a keyed App style plus `BasedOn` in the page style. <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
…sources (#40325) <!-- 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! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). For .NET 11 fixes, only a maintainer retargets the approved PR to the active inflight lane and merges it after CI validates that final base. Do not merge individual fixes directly into `net11`; agents must not retarget or merge. ### Description of Change Setting `Application.MainPage` to a page that has its own implicit style let the Application's implicit style for the same type override the page's style. **Root cause:** since #21879 (9.0), the `MainPage` setter pushes the app's merged resources with `value.OnResourcesChanged(...)`. That skips the "own keys win" filter in `VisualElement.OnParentResourcesChanged`. As a result, keys that the page defines itself, such as the implicit-style key `Microsoft.Maui.Controls.Button`, were overwritten by the Application's values. **Fix:** call `value.OnParentResourcesChanged(...)` instead. The Application's resources still reach the page, including theme propagation from #21879, but the page's own keys take precedence again. This is the same path `Element.Parent` uses. Reproduced with the 9.0.120 and 10.0.41 packages. 7.0.101 and 8.0.3 behave correctly. **Tests** - New `StyleTests.PageImplicitStyleWinsOverApplicationImplicitStyleWhenSetAsMainPage`: fails without the fix and passes with it. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter "FullyQualifiedName~Maui21774|FullyQualifiedName~Maui16538|FullyQualifiedName~AppTheme|FullyQualifiedName~DynamicResource|FullyQualifiedName~Style"`: passed (190/190). - `dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj`: 6734 passed and 1 failed. The failure, `TwoWayBindingToNullableDoublePropertyWithEmptyStringBecomesNull`, also fails on `net11` without this change. - `CorrectDefaultRadioButtonThemeColorsInLightAndDarkModes` fails in a filtered 150-test run with or without the fix. It passes in a smaller AppTheme-only run, so it depends on test order. ### Issues Fixed Relates to #20679. This fixes the 9.0 page-versus-Application precedence regression found while investigating that issue. The scenario in #20679 itself is by design: implicit styles from different resource levels don't merge, and `CanCascade` doesn't change that. The workaround is a keyed App style plus `BasedOn` in the page style. <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
…sources (#40325) <!-- 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! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). For .NET 11 fixes, only a maintainer retargets the approved PR to the active inflight lane and merges it after CI validates that final base. Do not merge individual fixes directly into `net11`; agents must not retarget or merge. ### Description of Change Setting `Application.MainPage` to a page that has its own implicit style let the Application's implicit style for the same type override the page's style. **Root cause:** since #21879 (9.0), the `MainPage` setter pushes the app's merged resources with `value.OnResourcesChanged(...)`. That skips the "own keys win" filter in `VisualElement.OnParentResourcesChanged`. As a result, keys that the page defines itself, such as the implicit-style key `Microsoft.Maui.Controls.Button`, were overwritten by the Application's values. **Fix:** call `value.OnParentResourcesChanged(...)` instead. The Application's resources still reach the page, including theme propagation from #21879, but the page's own keys take precedence again. This is the same path `Element.Parent` uses. Reproduced with the 9.0.120 and 10.0.41 packages. 7.0.101 and 8.0.3 behave correctly. **Tests** - New `StyleTests.PageImplicitStyleWinsOverApplicationImplicitStyleWhenSetAsMainPage`: fails without the fix and passes with it. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter "FullyQualifiedName~Maui21774|FullyQualifiedName~Maui16538|FullyQualifiedName~AppTheme|FullyQualifiedName~DynamicResource|FullyQualifiedName~Style"`: passed (190/190). - `dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj`: 6734 passed and 1 failed. The failure, `TwoWayBindingToNullableDoublePropertyWithEmptyStringBecomesNull`, also fails on `net11` without this change. - `CorrectDefaultRadioButtonThemeColorsInLightAndDarkModes` fails in a filtered 150-test run with or without the fix. It passes in a smaller AppTheme-only run, so it depends on test order. ### Issues Fixed Relates to #20679. This fixes the 9.0 page-versus-Application precedence regression found while investigating that issue. The scenario in #20679 itself is by design: implicit styles from different resource levels don't merge, and `CanCascade` doesn't change that. The workaround is a keyed App style plus `BasedOn` in the page style. <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
…sources (#40325) <!-- 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! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). For .NET 11 fixes, only a maintainer retargets the approved PR to the active inflight lane and merges it after CI validates that final base. Do not merge individual fixes directly into `net11`; agents must not retarget or merge. ### Description of Change Setting `Application.MainPage` to a page that has its own implicit style let the Application's implicit style for the same type override the page's style. **Root cause:** since #21879 (9.0), the `MainPage` setter pushes the app's merged resources with `value.OnResourcesChanged(...)`. That skips the "own keys win" filter in `VisualElement.OnParentResourcesChanged`. As a result, keys that the page defines itself, such as the implicit-style key `Microsoft.Maui.Controls.Button`, were overwritten by the Application's values. **Fix:** call `value.OnParentResourcesChanged(...)` instead. The Application's resources still reach the page, including theme propagation from #21879, but the page's own keys take precedence again. This is the same path `Element.Parent` uses. Reproduced with the 9.0.120 and 10.0.41 packages. 7.0.101 and 8.0.3 behave correctly. **Tests** - New `StyleTests.PageImplicitStyleWinsOverApplicationImplicitStyleWhenSetAsMainPage`: fails without the fix and passes with it. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter "FullyQualifiedName~Maui21774|FullyQualifiedName~Maui16538|FullyQualifiedName~AppTheme|FullyQualifiedName~DynamicResource|FullyQualifiedName~Style"`: passed (190/190). - `dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj`: 6734 passed and 1 failed. The failure, `TwoWayBindingToNullableDoublePropertyWithEmptyStringBecomesNull`, also fails on `net11` without this change. - `CorrectDefaultRadioButtonThemeColorsInLightAndDarkModes` fails in a filtered 150-test run with or without the fix. It passes in a smaller AppTheme-only run, so it depends on test order. ### Issues Fixed Relates to #20679. This fixes the 9.0 page-versus-Application precedence regression found while investigating that issue. The scenario in #20679 itself is by design: implicit styles from different resource levels don't merge, and `CanCascade` doesn't change that. The workaround is a keyed App style plus `BasedOn` in the page style. <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
…sources (#40325) <!-- 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! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). For .NET 11 fixes, only a maintainer retargets the approved PR to the active inflight lane and merges it after CI validates that final base. Do not merge individual fixes directly into `net11`; agents must not retarget or merge. ### Description of Change Setting `Application.MainPage` to a page that has its own implicit style let the Application's implicit style for the same type override the page's style. **Root cause:** since #21879 (9.0), the `MainPage` setter pushes the app's merged resources with `value.OnResourcesChanged(...)`. That skips the "own keys win" filter in `VisualElement.OnParentResourcesChanged`. As a result, keys that the page defines itself, such as the implicit-style key `Microsoft.Maui.Controls.Button`, were overwritten by the Application's values. **Fix:** call `value.OnParentResourcesChanged(...)` instead. The Application's resources still reach the page, including theme propagation from #21879, but the page's own keys take precedence again. This is the same path `Element.Parent` uses. Reproduced with the 9.0.120 and 10.0.41 packages. 7.0.101 and 8.0.3 behave correctly. **Tests** - New `StyleTests.PageImplicitStyleWinsOverApplicationImplicitStyleWhenSetAsMainPage`: fails without the fix and passes with it. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter "FullyQualifiedName~Maui21774|FullyQualifiedName~Maui16538|FullyQualifiedName~AppTheme|FullyQualifiedName~DynamicResource|FullyQualifiedName~Style"`: passed (190/190). - `dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj`: 6734 passed and 1 failed. The failure, `TwoWayBindingToNullableDoublePropertyWithEmptyStringBecomesNull`, also fails on `net11` without this change. - `CorrectDefaultRadioButtonThemeColorsInLightAndDarkModes` fails in a filtered 150-test run with or without the fix. It passes in a smaller AppTheme-only run, so it depends on test order. ### Issues Fixed Relates to #20679. This fixes the 9.0 page-versus-Application precedence regression found while investigating that issue. The scenario in #20679 itself is by design: implicit styles from different resource levels don't merge, and `CanCascade` doesn't change that. The workaround is a keyed App style plus `BasedOn` in the page style. <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
…sources (#40325) <!-- 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! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). For .NET 11 fixes, only a maintainer retargets the approved PR to the active inflight lane and merges it after CI validates that final base. Do not merge individual fixes directly into `net11`; agents must not retarget or merge. ### Description of Change Setting `Application.MainPage` to a page that has its own implicit style let the Application's implicit style for the same type override the page's style. **Root cause:** since #21879 (9.0), the `MainPage` setter pushes the app's merged resources with `value.OnResourcesChanged(...)`. That skips the "own keys win" filter in `VisualElement.OnParentResourcesChanged`. As a result, keys that the page defines itself, such as the implicit-style key `Microsoft.Maui.Controls.Button`, were overwritten by the Application's values. **Fix:** call `value.OnParentResourcesChanged(...)` instead. The Application's resources still reach the page, including theme propagation from #21879, but the page's own keys take precedence again. This is the same path `Element.Parent` uses. Reproduced with the 9.0.120 and 10.0.41 packages. 7.0.101 and 8.0.3 behave correctly. **Tests** - New `StyleTests.PageImplicitStyleWinsOverApplicationImplicitStyleWhenSetAsMainPage`: fails without the fix and passes with it. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter "FullyQualifiedName~Maui21774|FullyQualifiedName~Maui16538|FullyQualifiedName~AppTheme|FullyQualifiedName~DynamicResource|FullyQualifiedName~Style"`: passed (190/190). - `dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj`: 6734 passed and 1 failed. The failure, `TwoWayBindingToNullableDoublePropertyWithEmptyStringBecomesNull`, also fails on `net11` without this change. - `CorrectDefaultRadioButtonThemeColorsInLightAndDarkModes` fails in a filtered 150-test run with or without the fix. It passes in a smaller AppTheme-only run, so it depends on test order. ### Issues Fixed Relates to #20679. This fixes the 9.0 page-versus-Application precedence regression found while investigating that issue. The scenario in #20679 itself is by design: implicit styles from different resource levels don't merge, and `CanCascade` doesn't change that. The workaround is a keyed App style plus `BasedOn` in the page style. <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
…sources (#40325) <!-- 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! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). For .NET 11 fixes, only a maintainer retargets the approved PR to the active inflight lane and merges it after CI validates that final base. Do not merge individual fixes directly into `net11`; agents must not retarget or merge. ### Description of Change Setting `Application.MainPage` to a page that has its own implicit style let the Application's implicit style for the same type override the page's style. **Root cause:** since #21879 (9.0), the `MainPage` setter pushes the app's merged resources with `value.OnResourcesChanged(...)`. That skips the "own keys win" filter in `VisualElement.OnParentResourcesChanged`. As a result, keys that the page defines itself, such as the implicit-style key `Microsoft.Maui.Controls.Button`, were overwritten by the Application's values. **Fix:** call `value.OnParentResourcesChanged(...)` instead. The Application's resources still reach the page, including theme propagation from #21879, but the page's own keys take precedence again. This is the same path `Element.Parent` uses. Reproduced with the 9.0.120 and 10.0.41 packages. 7.0.101 and 8.0.3 behave correctly. **Tests** - New `StyleTests.PageImplicitStyleWinsOverApplicationImplicitStyleWhenSetAsMainPage`: fails without the fix and passes with it. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter "FullyQualifiedName~Maui21774|FullyQualifiedName~Maui16538|FullyQualifiedName~AppTheme|FullyQualifiedName~DynamicResource|FullyQualifiedName~Style"`: passed (190/190). - `dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj`: 6734 passed and 1 failed. The failure, `TwoWayBindingToNullableDoublePropertyWithEmptyStringBecomesNull`, also fails on `net11` without this change. - `CorrectDefaultRadioButtonThemeColorsInLightAndDarkModes` fails in a filtered 150-test run with or without the fix. It passes in a smaller AppTheme-only run, so it depends on test order. ### Issues Fixed Relates to #20679. This fixes the 9.0 page-versus-Application precedence regression found while investigating that issue. The scenario in #20679 itself is by design: implicit styles from different resource levels don't merge, and `CanCascade` doesn't change that. The workaround is a keyed App style plus `BasedOn` in the page style. <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
…sources (dotnet#40325) <!-- 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! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). For .NET 11 fixes, only a maintainer retargets the approved PR to the active inflight lane and merges it after CI validates that final base. Do not merge individual fixes directly into `net11`; agents must not retarget or merge. ### Description of Change Setting `Application.MainPage` to a page that has its own implicit style let the Application's implicit style for the same type override the page's style. **Root cause:** since dotnet#21879 (9.0), the `MainPage` setter pushes the app's merged resources with `value.OnResourcesChanged(...)`. That skips the "own keys win" filter in `VisualElement.OnParentResourcesChanged`. As a result, keys that the page defines itself, such as the implicit-style key `Microsoft.Maui.Controls.Button`, were overwritten by the Application's values. **Fix:** call `value.OnParentResourcesChanged(...)` instead. The Application's resources still reach the page, including theme propagation from dotnet#21879, but the page's own keys take precedence again. This is the same path `Element.Parent` uses. Reproduced with the 9.0.120 and 10.0.41 packages. 7.0.101 and 8.0.3 behave correctly. **Tests** - New `StyleTests.PageImplicitStyleWinsOverApplicationImplicitStyleWhenSetAsMainPage`: fails without the fix and passes with it. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter "FullyQualifiedName~Maui21774|FullyQualifiedName~Maui16538|FullyQualifiedName~AppTheme|FullyQualifiedName~DynamicResource|FullyQualifiedName~Style"`: passed (190/190). - `dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj`: 6734 passed and 1 failed. The failure, `TwoWayBindingToNullableDoublePropertyWithEmptyStringBecomesNull`, also fails on `net11` without this change. - `CorrectDefaultRadioButtonThemeColorsInLightAndDarkModes` fails in a filtered 150-test run with or without the fix. It passes in a smaller AppTheme-only run, so it depends on test order. ### Issues Fixed Relates to dotnet#20679. This fixes the 9.0 page-versus-Application precedence regression found while investigating that issue. The scenario in dotnet#20679 itself is by design: implicit styles from different resource levels don't merge, and `CanCascade` doesn't change that. The workaround is a keyed App style plus `BasedOn` in the page style. <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
…ascade (#41028) <!-- 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! ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). For .NET 11 fixes, only a maintainer retargets the approved PR to the active inflight lane and merges it after CI validates that final base. Do not merge individual fixes directly into `net11`; agents must not retarget or merge. ### Description of Change **Problem (#20679):** In .NET 7, an implicit `Button` style in `Application.Resources` and another in `ContentPage.Resources` both appeared to apply. Since .NET 8, only the nearest one (the page style) applies. **Root cause:** The .NET 7 behavior was accidental. The app's implicit style was applied while the element was still unparented, through the `Application.Current` fallback. When the page style replaced it, those values were never fully unapplied. The style-specificity work (#13818) correctly unapplies replaced styles, which removed the leak. Since then, `Style.CanCascade` has had no effect. #40325 (already in `net11`) fixed a different Application/MainPage precedence bug and does not change this. **Fix:** This PR gives `Style.CanCascade` an explicit opt-in meaning for implicit styles: - When the nearest implicit style has `CanCascade="True"`, the implicit styles for the **same key** further up the resource chain (parent elements, then `Application`) are applied *underneath* it. Each one gets a lower `SetterSpecificity` (`StyleImplicit - 1 - depth`), so nearer styles always win. - The cascade continues as long as each added style also has `CanCascade`. - An outer style is skipped when its `TargetType` doesn't apply, when it is a base-type key without `ApplyToDerivedTypes`, or when it is already included through `BasedOn`. - Default behavior (`CanCascade=false`) is unchanged. Changes: - `MergedStyle`: computes and applies or unapplies the cascaded implicit styles, and recomputes them when relevant resource keys change. - `ResourcesExtensions.GetResourcesAlongParentChain`: enumerates values for a key, nearest first, ending with `Application.Current`. - `VisualElement` / `Element` / `ResourceDictionary`: when an ancestor is (re)parented, a key shadowed by a local `CanCascade` style is still forwarded to descendants, so their cascade is refreshed. XAML builds bottom-up, so this is needed. Lazy (unmaterialized) resources are not resolved. - `Style.CanCascade` docs updated. **Usage:** ```xml <ContentPage.Resources> <Style TargetType="Button" CanCascade="True"> <Setter Property="BorderColor" Value="Red" /> </Style> </ContentPage.Resources> ``` With this, the app-level implicit `Button` style also applies, and the page style overrides any shared properties. Alternative without this PR: `BasedOn="{StaticResource Microsoft.Maui.Controls.Button}"` (not verified here). **Known limitations:** - Removing a key with `ResourceDictionary.Remove` doesn't raise change notifications. This is existing behavior, so removal isn't reflected; replacing the key is. - Only the same key as the nearest implicit style is cascaded. ### Testing New tests: - `StyleTests` (Controls.Core.UnitTests): - `ImplicitStyleWithCanCascadeAlsoAppliesOuterImplicitStyle` - `CascadedImplicitStylesAreUnappliedWithTheCascadingStyle` (nested view/page/app, then replacing styles) - `ImplicitStyleWithoutCanCascadeReplacesOuterImplicitStyle` (guards the default behavior) - `Maui20679` (Xaml.UnitTests): XAML repro for all inflators. Commands and results: - `dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter "FullyQualifiedName~Style"`: **passed**, 207/207. - Red check with `src/Controls/src/Core` changes stashed, filter `FullyQualifiedName~Cascad`: **2 failed** (the two cascade tests), 91 passed. - `dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj` (full): 6837 passed, 6 failed, 30 skipped. The same 6 `HostBuilderAppTests` failures (`ObjectDisposedException` in `DispatcherProviderStub`) also fail on the unmodified `net11` baseline (6834 passed, 6 failed), so they are unrelated. - `Maui20679` XAML test: **not run locally**. `dotnet build Microsoft.Maui.BuildTasks.slnf` fails in this environment with NU1605 (HarfBuzzSharp/SkiaSharp package downgrade in Resizetizer; feed access issue). It is left for CI. ### Issues Fixed Fixes #20679 ### Let AI finish this PR - [ ] **Let the MAUI agent address review feedback and fix remaining issues on this PR.** Maintainers still decide whether it is merged. For PRs from forks, the agent opens a follow-up PR that keeps your commits. --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
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 if this change resolves your issue. Thank you!
Target Branch
mainnet11, for reviewFor .NET 11 fixes, only a maintainer retargets the approved PR to the active
inflight lane and merges it after CI validates that final base. Do not merge
individual fixes directly into
net11; agents must not retarget or merge.Description of Change
Setting
Application.MainPageto a page that has its own implicit style let the Application's implicit style for the same type override the page's style.Root cause: since #21879 (9.0), the
MainPagesetter pushes the app's merged resources withvalue.OnResourcesChanged(...). That skips the "own keys win" filter inVisualElement.OnParentResourcesChanged. As a result, keys that the page defines itself, such as the implicit-style keyMicrosoft.Maui.Controls.Button, were overwritten by the Application's values.Fix: call
value.OnParentResourcesChanged(...)instead. The Application's resources still reach the page, including theme propagation from #21879, but the page's own keys take precedence again. This is the same pathElement.Parentuses.Reproduced with the 9.0.120 and 10.0.41 packages. 7.0.101 and 8.0.3 behave correctly.
Tests
StyleTests.PageImplicitStyleWinsOverApplicationImplicitStyleWhenSetAsMainPage: fails without the fix and passes with it.dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter "FullyQualifiedName~Maui21774|FullyQualifiedName~Maui16538|FullyQualifiedName~AppTheme|FullyQualifiedName~DynamicResource|FullyQualifiedName~Style": passed (190/190).dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj: 6734 passed and 1 failed. The failure,TwoWayBindingToNullableDoublePropertyWithEmptyStringBecomesNull, also fails onnet11without this change.CorrectDefaultRadioButtonThemeColorsInLightAndDarkModesfails in a filtered 150-test run with or without the fix. It passes in a smaller AppTheme-only run, so it depends on test order.Issues Fixed
Relates to #20679. This fixes the 9.0 page-versus-Application precedence regression found while investigating that issue. The scenario in #20679 itself is by design: implicit styles from different resource levels don't merge, and
CanCascadedoesn't change that. The workaround is a keyed App style plusBasedOnin the page style.