-
Notifications
You must be signed in to change notification settings - Fork 2k
[XAML] SourceGen: Compile RelativeSource AncestorType bindings under AOT #34408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
500fc59
fix-34056 – Updated SourceGen to generate compiled bindings for Relat…
BagavathiPerumal 557d6e6
fix-34056-Changes updated.
BagavathiPerumal eb322d0
fix-34056-made code changes to address review concerns by adding isAn…
BagavathiPerumal eda84d9
fix-34056-Optimized the code change and added testcase for edge case …
BagavathiPerumal bf8ca0f
fix-34056-Removed the unwated test script.
BagavathiPerumal 71b5099
fix-34056-Updated the diagnostic suppression condition, test comments…
BagavathiPerumal d47af06
fix-34056-Comments and testcase updated.
BagavathiPerumal 4463214
fix-34056-Testcase added and comment updated.
BagavathiPerumal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
| xmlns:local="clr-namespace:Microsoft.Maui.Controls.Xaml.UnitTests" | ||
| x:Class="Microsoft.Maui.Controls.Xaml.UnitTests.Maui34056" | ||
| x:DataType="local:Maui34056PageViewModel"> | ||
| <VerticalStackLayout> | ||
| <!-- Scenario 1: RelativeSource AncestorType inside DataTemplate with x:DataType (issue fix). | ||
| Mirrors the exact user reproduction case (inline x:DataType matches AncestorType). --> | ||
| <CollectionView x:Name="TestCollectionView" | ||
| ItemsSource="{Binding Items}"> | ||
| <CollectionView.ItemTemplate> | ||
| <DataTemplate x:DataType="local:Maui34056ItemViewModel"> | ||
| <Button x:Name="TestButton" | ||
| Text="{Binding ItemName}" | ||
| Command="{Binding x:DataType='local:Maui34056PageViewModel', Source={RelativeSource AncestorType={x:Type local:Maui34056PageViewModel}}, Path=TestCommand}" /> | ||
|
BagavathiPerumal marked this conversation as resolved.
|
||
| </DataTemplate> | ||
| </CollectionView.ItemTemplate> | ||
| </CollectionView> | ||
|
|
||
| <!-- Scenario 2: {RelativeSource Self} inside DataTemplate with x:DataType. | ||
| SourceGen must not use x:DataType as the source type; the source is the element itself. | ||
| Path=ItemName exists on Maui34056ItemViewModel to ensure the guard, not a failed lookup, prevents compiled binding. --> | ||
| <CollectionView x:Name="SelfBindingCollectionView" | ||
| ItemsSource="{Binding Items}"> | ||
| <CollectionView.ItemTemplate> | ||
| <DataTemplate x:DataType="local:Maui34056ItemViewModel"> | ||
| <Label x:Name="SelfBindingLabel" | ||
| Text="{Binding Path=ItemName, Source={RelativeSource Self}}" /> | ||
| </DataTemplate> | ||
| </CollectionView.ItemTemplate> | ||
| </CollectionView> | ||
| <!-- Scenario 3: RelativeSource AncestorType without inline x:DataType (regression guard). | ||
| The ambient DataTemplate x:DataType is Maui34056ItemViewModel, which has no TestCommand. | ||
| If SourceGen regressed and used ambient x:DataType instead of AncestorType as the source, | ||
| it would produce a different TypedBinding or fall back to runtime Binding, and the | ||
| TypedBinding<Maui34056PageViewModel, ICommand> assertion would fail, catching the regression. --> | ||
| <CollectionView x:Name="AncestorTypeNoInlineDataTypeCollectionView" | ||
| ItemsSource="{Binding Items}"> | ||
| <CollectionView.ItemTemplate> | ||
| <DataTemplate x:DataType="local:Maui34056ItemViewModel"> | ||
| <Button x:Name="AncestorTypeNoInlineDataTypeButton" | ||
| Text="{Binding ItemName}" | ||
| Command="{Binding Source={RelativeSource AncestorType={x:Type local:Maui34056PageViewModel}}, Path=TestCommand}" /> | ||
| </DataTemplate> | ||
| </CollectionView.ItemTemplate> | ||
| </CollectionView> | ||
| <!-- Scenario 4: RelativeSource AncestorType for an Element subclass (ContentPage). | ||
| AncestorType=ContentPage derives from Element, so SourceGen selects FindAncestor mode | ||
| (not FindAncestorBindingContext). This verifies the HasImplicitConversion branch in | ||
| KnownMarkups.TryGetRelativeSourceAncestorType produces the correct mode. --> | ||
| <CollectionView x:Name="FindAncestorCollectionView" | ||
| ItemsSource="{Binding Items}"> | ||
| <CollectionView.ItemTemplate> | ||
| <DataTemplate x:DataType="local:Maui34056ItemViewModel"> | ||
| <Label x:Name="FindAncestorLabel" | ||
| Text="{Binding Source={RelativeSource AncestorType={x:Type ContentPage}}, Path=Title}" /> | ||
| </DataTemplate> | ||
| </CollectionView.ItemTemplate> | ||
| </CollectionView> | ||
| </VerticalStackLayout> | ||
| </ContentPage> | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.