[backport 10.0.1xx-sr5] Fix MAUIG2045 false positive with x:Reference source in DataTemplate#34525
Merged
jfversluis merged 1 commit intorelease/10.0.1xx-sr5from Mar 18, 2026
Conversation
When Source={x:Reference} is used in a binding inside a DataTemplate,
the source generator incorrectly resolves the Path against the
DataTemplate's x:DataType instead of the referenced element's type.
The fix resolves the x:Reference target's type via namescope lookup
and compiles the binding path against that type. For example,
Source={x:Reference PageRoot} with Path=BindingContext.SelectItemCommand
now resolves against ContentPage (the referenced element) instead of
ItemModel (the DataTemplate's x:DataType).
Fixes #34490
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 34525Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 34525" |
Contributor
There was a problem hiding this comment.
Pull request overview
Backport to release/10.0.1xx-sr5 that fixes a MAUIG2045 false positive in the XAML source generator when a Binding inside a DataTemplate uses an explicit Source={x:Reference ...}. The generator now recognizes explicit sources and avoids validating/compiling the binding against the current x:DataType scope, preventing incorrect “property not found” warnings.
Changes:
- Update SourceGen binding handling to treat
Source={RelativeSource ...}andSource={x:Reference ...}as explicit sources and skip compiled binding generation. - Add a SourceGen unit test ensuring the false-positive MAUIG2045 is not reported for
x:Referencesource bindings inside aDataTemplate. - Add a XAML unit test page + test harness reproducing the scenario across inflators.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Controls/src/SourceGen/KnownMarkups.cs | Detects ReferenceExtension/Reference in Binding.Source and skips compiled binding when Source is explicitly set. |
| src/Controls/tests/SourceGen.UnitTests/BindingDiagnosticsTests.cs | Adds regression test for x:Reference-sourced binding in a DataTemplate not producing the prior false-positive diagnostic. |
| src/Controls/tests/Xaml.UnitTests/Issues/Maui34490.xaml | Adds a minimal repro XAML using Source={x:Reference PageRoot} inside a DataTemplate with x:DataType. |
| src/Controls/tests/Xaml.UnitTests/Issues/Maui34490.xaml.cs | Adds inflator-spanning test with a SourceGen diagnostic assertion for the repro page. |
simonrozsival
approved these changes
Mar 18, 2026
Contributor
Author
|
/azp run maui-pr-uitests, maui-pr-devicetests |
|
Azure Pipelines successfully started running 2 pipeline(s). |
This was referenced Mar 18, 2026
This was referenced Mar 25, 2026
Merged
Open
evgenygunko
pushed a commit
to evgenygunko/CopyWordsDA
that referenced
this pull request
Mar 26, 2026
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [Microsoft.Maui.Controls](https://github.com/dotnet/maui) | nuget | patch | `10.0.50` -> `10.0.51` | --- ### Release Notes <details> <summary>dotnet/maui (Microsoft.Maui.Controls)</summary> ### [`v10.0.51`](https://github.com/dotnet/maui/releases/tag/10.0.51): SR5.1 [Compare Source](dotnet/maui@10.0.50...10.0.51) #### What's Changed - Increment patch version from 50 to 51 by [@​PureWeen](https://github.com/PureWeen) in dotnet/maui#34458 - \[release/10.0.1xx-sr5] \[Regression] Fix TypedBinding nested property re-subscription ([#​34428](dotnet/maui#34428)) by [@​github-actions](https://github.com/github-actions)\[bot] in dotnet/maui#34450 - \[backport 10.0.1xx-sr5] Fix MAUIG2045 false positive with x:Reference source in DataTemplate by [@​StephaneDelcroix](https://github.com/StephaneDelcroix) in dotnet/maui#34525 **Full Changelog**: dotnet/maui@10.0.50...10.0.51 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or PR is renamed to start with "rebase!". 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://github.com/renovatebot/renovate/discussions) if that's undesired. --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
This was referenced Mar 26, 2026
Open
Merged
TheCodeTraveler
pushed a commit
to TheCodeTraveler/MAUIChatGPTClone
that referenced
this pull request
Mar 26, 2026
Updated [Microsoft.Maui.Controls](https://github.com/dotnet/maui) from 10.0.50 to 10.0.51. <details> <summary>Release notes</summary> _Sourced from [Microsoft.Maui.Controls's releases](https://github.com/dotnet/maui/releases)._ ## 10.0.51 ## What's Changed * Increment patch version from 50 to 51 by @PureWeen in dotnet/maui#34458 * [release/10.0.1xx-sr5] [Regression] Fix TypedBinding nested property re-subscription (#34428) by @github-actions[bot] in dotnet/maui#34450 * [backport 10.0.1xx-sr5] Fix MAUIG2045 false positive with x:Reference source in DataTemplate by @StephaneDelcroix in dotnet/maui#34525 **Full Changelog**: dotnet/maui@10.0.50...10.0.51 Commits viewable in [compare view](dotnet/maui@10.0.50...10.0.51). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This was referenced Mar 27, 2026
This was referenced Mar 30, 2026
Open
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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!
Description
Backport of #34501 to
release/10.0.1xx-sr5.When a binding uses
Source={x:Reference}, the source generator was incorrectly validating the binding path againstx:DataTypeinstead of the referenced element, producing a false MAUIG2045 warning. This fix detects explicit binding sources (bothRelativeSourceandx:Reference) and skips compilation, falling back to runtime binding.Fixes #34490