Open simonrozsival opened 7 months ago
Will this still be part of .NET 9? I'm afraid a lot of people will run into this via #23711 if they are upgrading from .NET 9
@hansmbakker it's not likely this will be in .NET 9. It's true that the issue you linked shows that people might find it difficult to upgrade to .NET 9 in certain scenarios and we need to do something about it (most likely better warning messages).
I don't think implementing the type inference the way I outlined it in this issue would fix that issue though. The problem there is that the Path
can only be resolved at runtime via reflection and it cannot be compiled ahead of time because we don't know the type of object BindingContext
and we don't have a way to specify a cast at the moment.
Without this we'll not be able to compile app with .net9 as we need to use binding to Source{x:Reference
@awasilik This should work:
-<RowDefinition Height="{Binding HeightRequest, Source={x:Reference thisControl}}"/>
+<RowDefinition Height="{Binding HeightRequest, Source={x:Reference thisControl}, x:DataType={x:Null}}"/>
However, yes, it requires manual changes in code.
In certain scenarios, XamlC should be able to infer the
x:DataType
based on the value passed toBindingContext
on any XAML element or toSource
onBindingExtension
elements:{StaticResource X}
- in the case whenX
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 knownFindAncestor
FindAncestorBindingContext
- when the ancestor and the type of the binding context can be statically resolvedTemplatedParent
- when the templated parent can be statically resolvedExplicitly 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