-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
XAML Page Binding to Self Gets Incorrect Warning #25271
Comments
Unfortunately, we can't infer the data type from TL;DR add
Longer answer: The
class ViewModelA
{
public ViewModelB ViewModelB { get; set; }
}
class ViewModelB
{
public Color Color { get; set; }
} In this example, we set the binding context of B to I see how this seems strange in your code where you're setting the |
Thanks @simonrozsival, that makes sense but leaves the problem that if I use: BindingContext="{Binding Source={RelativeSource Self}}" At the Page level I always get the warning The only workaround to eliminate the warning that I could come up with was to move the BindingContext initialization into code behind and just set Does anyone have any other ideas, or shall I go ahead and just move the |
@david-maw you should be able to fix this by using the binding this way:
Setting the BindingContext in the constructor is going to be negligibly faster (there's no need to allocate the instance of the binding), but effectively equivalent. Please feel free to close the issue if this solves the issue. |
Thanks @simonrozsival, that works, no idea how I've gone this long without realizing you could embed an x:DataType in a XAML Binding specification. |
Description
If a XAML page uses itself as a binding context it will get the following warning from the XAML compiler
Binding could be compiled to improve runtime performance if x:DataType is specified. See https://learn.microsoft.com/dotnet/maui/fundamentals/data-binding/compiled-bindings for more information.
It gets this warning even if x:DataType is specified.
Steps to Reproduce
Then build it and observe the warning. At the very least it's not clear what it is suggesting.
Link to public reproduction project repository
https://github.com/david-maw/SelfBinding.git
Version with bug
9.0.0-rc.2.24503.2
Is this a regression from previous behavior?
No, this is something new
Last version that worked well
Unknown/Other
Affected platforms
Windows, I was not able test on other platforms
Affected platform versions
Windows 11 at compile time
Did you find any workaround?
No
Relevant log output
No response
The text was updated successfully, but these errors were encountered: