-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[XC] Compile bindings with Source #20610
[XC] Compile bindings with Source #20610
Conversation
we can not start compiling Bindings with Source before we support x:DataType at the binding level, or we'll get issues with syntax like this <Label x:Name="other" />
<Label x:DataType="viewModel"
Text={Binding foo} //binding on view model.foo
TextColor={Binding TextColor, Source={x:Refererence other}} // will fail
/> Also, in case the source can be determined (like x:Reference), we might not even need a DataType to proceed with compilation |
I'm not sure what exactly you mean. This binding is compiled correctly using the code in this branch: <Label
Text="{Binding Text, x:DataType=Button, Source={x:Reference CounterBtn}}"
Style="{StaticResource SubHeadline}"
SemanticProperties.HeadingLevel="Level2"
SemanticProperties.Description="Welcome to dot net Multi platform App U I" />
<Button
x:Name="CounterBtn"
Text="Click me"
SemanticProperties.Hint="Counts the number of times you click"
Clicked="OnCounterClicked"
HorizontalOptions="Fill" /> Decompiled assembly: // ...
referenceExtension.Name = "CounterBtn";
XamlServiceProvider xamlServiceProvider2 = new XamlServiceProvider();
Type typeFromHandle3 = typeof(IProvideValueTarget);
object[] array2 = new object[0 + 5];
array2[0] = bindingExtension;
array2[1] = label2;
array2[2] = verticalStackLayout;
array2[3] = scrollView;
array2[4] = mainPage;
object obj2;
xamlServiceProvider2.Add(typeFromHandle3, obj2 = new SimpleValueTargetProvider(array2, typeof(BindingExtension).GetRuntimeProperty("Source"), new NameScope[6] { nameScope, nameScope, nameScope, nameScope, nameScope, nameScope }, false));
xamlServiceProvider2.Add(typeof(IReferenceProvider), obj2);
Type typeFromHandle4 = typeof(IXamlTypeResolver);
XmlNamespaceResolver xmlNamespaceResolver2 = new XmlNamespaceResolver();
xmlNamespaceResolver2.Add("", "http://schemas.microsoft.com/dotnet/2021/maui");
xmlNamespaceResolver2.Add("x", "http://schemas.microsoft.com/winfx/2009/xaml");
xamlServiceProvider2.Add(typeFromHandle4, new XamlTypeResolver(xmlNamespaceResolver2, typeof(MainPage).Assembly));
xamlServiceProvider2.Add(typeof(IXmlLineInfoProvider), new XmlLineInfoProvider(new XmlLineInfo(22, 17)));
object source = ((IMarkupExtension)referenceExtension).ProvideValue((IServiceProvider)xamlServiceProvider2);
bindingExtension.Source = source;
bindingExtension.Path = "Text";
bindingExtension.TypedBinding = new TypedBinding<Button, string>((Button P_0) => (P_0 != null) ? (P_0.Text, true) : default((string, bool)), delegate(Button P_0, string P_1)
{
if (P_0 != null)
{
P_0.Text = P_1;
}
}, new Tuple<Func<Button, object>, string>[1]
{
new Tuple<Func<Button, object>, string>((Button P_0) => P_0, "Text")
});
BindingBase binding = ((IMarkupExtension<BindingBase>)bindingExtension).ProvideValue((IServiceProvider)null);
label2.SetBinding(Label.TextProperty, binding);
// ...
I agree that that should be supported as well. But I think that could be implemented in a separate PR. |
BTW looking at the decompiled code more closely, it doesn't seem we don't compile the |
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.
Build is failing for windows. Also if you can rebase :)
Issue9417.xaml(43,37): XamlC error XFC0045: Binding: Property "BindingContext" not found on "Microsoft.Maui.Controls.ControlGallery.Issues.Issue9417Model". [D:\a\_work\1\s\src\Compatibility\ControlGallery\src\Core\Compatibility.ControlGallery.Core.csproj]
Issue11764.xaml(29,37): XamlC error XFC0045: Binding: Property "BindingContext" not found on "System.String". [D:\a\_work\1\s\src\Compatibility\ControlGallery\src\Core\Compatibility.ControlGallery.Core.csproj]
Issue11831.xaml(57,41): XamlC error XFC0045: Binding: Property "BindingContext" not found on "System.String". [D:\a\_work\1\s\src\Compatibility\ControlGallery\src\Core\Compatibility.ControlGallery.Core.csproj]
7010 Warning(s)
3 Error(s)
…yped-binding-source-compilation-restriction
@rmarinho the remaining failing tests seem to be unrelated |
Description of Change
Currently, we're skipping compilation of bindings which have Source. The reason was that there wasn't support for relative binding sources until recently. Since #20415 has been merged into
net9.0
, we can now safely compile bindings which have aSource
property.Issues Fixed
Contributes to #20266