-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[XSG] Skip compiled binding when RelativeSource is used #33248
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <?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.Maui33247" | ||
| x:DataType="local:Maui33247"> | ||
| <!-- Test: RelativeSource AncestorType with Path=. should return the ContentPage itself --> | ||
| <Grid x:Name="MainGrid" BackgroundColor="Blue"> | ||
| <Grid.GestureRecognizers> | ||
| <TapGestureRecognizer x:Name="DirectTapGesture" | ||
| Command="{Binding Navigate}" | ||
| CommandParameter="{Binding Path=., Source={RelativeSource AncestorType={x:Type local:Maui33247}}}" /> | ||
| </Grid.GestureRecognizers> | ||
| <Label Text="Direct binding test" /> | ||
| </Grid> | ||
| </ContentPage> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| using System.Windows.Input; | ||
|
||
| using Xunit; | ||
|
|
||
| namespace Microsoft.Maui.Controls.Xaml.UnitTests; | ||
|
|
||
| /// <summary> | ||
| /// Test for regression: RelativeSource AncestorType with Path=. returns null in v10.0.20 | ||
| /// | ||
| /// Scenario: A TapGestureRecognizer tries to get a reference to the parent ContentPage via | ||
| /// CommandParameter="{Binding Path=., Source={RelativeSource AncestorType={x:Type local:Maui33247}}}" | ||
| /// | ||
| /// Expected: The CommandParameter should receive the ContentPage reference. | ||
| /// Bug: In v10.0.20, the CommandParameter was null when using SourceGen because the source generator | ||
| /// was incorrectly compiling the binding to use x:DataType as the source type instead of allowing | ||
| /// the RelativeSource to resolve the source at runtime. | ||
| /// | ||
| /// Fix: When a binding has a Source property with a RelativeSource, skip the compiled binding path | ||
| /// and use the fallback string-based binding instead. | ||
| /// </summary> | ||
| public partial class Maui33247 : ContentPage | ||
| { | ||
| public Maui33247() | ||
| { | ||
| InitializeComponent(); | ||
| BindingContext = this; | ||
| } | ||
|
|
||
| public ICommand Navigate => new Command((param) => { }); | ||
|
|
||
| [Collection("Issue")] | ||
| public class Tests | ||
| { | ||
| [Theory] | ||
| [XamlInflatorData] | ||
| internal void DirectRelativeSourceAncestorTypeWithSelfPathReturnsAncestor(XamlInflator inflator) | ||
| { | ||
| // Test that RelativeSource AncestorType with Path=. returns the ancestor object for direct children | ||
| var page = new Maui33247(inflator); | ||
|
|
||
| // The CommandParameter with RelativeSource AncestorType and Path=. should be the ContentPage itself | ||
| Assert.NotNull(page.DirectTapGesture.CommandParameter); | ||
| Assert.IsType<Maui33247>(page.DirectTapGesture.CommandParameter); | ||
| Assert.Same(page, page.DirectTapGesture.CommandParameter); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test file is named "Maui33500.xaml" but the PR description states this fixes issue #33247. According to XAML unit testing guidelines, test files for GitHub issues should be named "MauiXXXXX.xaml" where XXXXX is the GitHub issue number. This file should be renamed to "Maui33247.xaml" to match the issue being fixed.