dotnet / dotnet/maui

[XSG] Optimize compiled bindings for RelativeSource with explicit Source

Open
#33,249 1 comment 3 reactions 1 assignee Claimed by @simonrozsival View on GitHub
area-xaml s/triaged xsg
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 10h
Merged PRs (30d)
297

Description

### Description

PR #33248 fixed a regression where bindings with `RelativeSource` and `Path=.` returned null. The fix skips the compiled binding path when a binding has a `Source` property with a `RelativeSourceExtension`, falling back to the string-based binding.

While this correctly fixes the bug, it disables binding source generation for these cases. We should revisit this to see if we can still generate optimized bindings while correctly handling the `RelativeSource` source resolution.

### Current Behavior (after fix)

When a binding has:
```xml
CommandParameter="{Binding Path=., Source={RelativeSource AncestorType={x:Type MainPage}}}"
```

The SourceGen now generates a regular `Binding` instead of a `TypedBinding`:
```csharp
var bindingBase = new Binding(path, mode, converter, ..., source);
```

### Potential Optimization

Consider if we can still generate a `TypedBinding` that:
1. Uses the `RelativeSource` resolved type as the source type (not `x:DataType`)
2. Correctly handles `Path=.` to return the resolved ancestor itself

### Related

- Fix PR: #33248
- Original issue: #33247

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.