Skip to content

[XC] Infer x:DataType from BindingContext or BindingExtension.Source #21834

@simonrozsival

Description

@simonrozsival

In certain scenarios, XamlC should be able to infer the x:DataType based on the value passed to BindingContext on any XAML element or to Source on BindingExtension elements:

  • {StaticResource X} - in the case when X is defined in the same XAML document
  • {x:Static Y}
  • {x:Reference Z}
  • {Binding W} - when the binding is compiled
  • {Binding Source={RelativeSource U}}:
    • Self - when the elemet to which the binding is set is statically known
    • FindAncestor
    • FindAncestorBindingContext - when the ancestor and the type of the binding context can be statically resolved
    • TemplatedParent - when the templated parent can be statically resolved

Explicitly declared x:DataType should always take precedence over the inferred type. In the case when there is a mismatch, we should consider emitting a warning.

Are there any other cases which we could infer?

/cc @StephaneDelcroix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions