Skip to content

[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
backport/34501-to-release-10.0.1xx-sr5
Mar 18, 2026
Merged

[backport 10.0.1xx-sr5] Fix MAUIG2045 false positive with x:Reference source in DataTemplate#34525
jfversluis merged 1 commit intorelease/10.0.1xx-sr5from
backport/34501-to-release-10.0.1xx-sr5

Conversation

@StephaneDelcroix
Copy link
Copy Markdown
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment 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 against x:DataType instead of the referenced element, producing a false MAUIG2045 warning. This fix detects explicit binding sources (both RelativeSource and x:Reference) and skips compilation, falling back to runtime binding.

Fixes #34490

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>
Copilot AI review requested due to automatic review settings March 18, 2026 09:20
@github-actions
Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

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

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

Or

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 ...} and Source={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:Reference source bindings inside a DataTemplate.
  • 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.

@StephaneDelcroix
Copy link
Copy Markdown
Contributor Author

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

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 2 pipeline(s).

@jfversluis jfversluis merged commit 638865c into release/10.0.1xx-sr5 Mar 18, 2026
172 of 175 checks passed
@jfversluis jfversluis deleted the backport/34501-to-release-10.0.1xx-sr5 branch March 18, 2026 15:32
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 [@&#8203;PureWeen](https://github.com/PureWeen) in dotnet/maui#34458
-   \[release/10.0.1xx-sr5] \[Regression] Fix TypedBinding nested property re-subscription ([#&#8203;34428](dotnet/maui#34428)) by [@&#8203;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 [@&#8203;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).
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>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=Microsoft.Maui.Controls&package-manager=nuget&previous-version=10.0.50&new-version=10.0.51)](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 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants