Skip to content

[XSG] Optimize compiled bindings for RelativeSource with explicit Source #33249

@StephaneDelcroix

Description

@StephaneDelcroix

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:

CommandParameter="{Binding Path=., Source={RelativeSource AncestorType={x:Type MainPage}}}"

The SourceGen now generates a regular Binding instead of a TypedBinding:

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

Metadata

Metadata

Assignees

Labels

area-xamlXAML, CSS, Triggers, Behaviorss/triagedIssue has been reviewedxsgXaml sourceGen

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions