-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Description
The following XAML snippet will result in failed compilation on a NOOB application as compiled XAML is the default for MAUI apps. Simply add it as a binding to any property.
<Binding Path="Foo" TargetNullValue="{x:Static Binding.DoNothing}"/>Specifically the following error code is returned:
Error XFC0101 x:Static: unable to find a public -- or accessible internal -- static field, static property, const or enum value named "DoNothing" in "Binding".
It would appear that string "Binding" is somehow special during type lookup in XAML compilation operations as using another static field from the same namespace Microsoft.Maui.Controls works without error:
<Binding Path="Foo" TargetNullValue="{x:Static Application.AccentColor}"/>Steps to Reproduce
- Create a new MAUI app
- Add the binding that causes error to one of the Image elements in MainPage.xaml
<Image.AnchorX>
<Binding Path="Foo" TargetNullValue="{x:Static Binding.DoNothing}"/>
</Image.AnchorX>- Compile
Link to public reproduction project repository
https://github.com/bakerhillpins/Issues/tree/NetMauiIssue11833
Version with bug
6.0 Release Candidate 2 or older
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android, Windows, macOS, Other (Tizen, Linux, etc. not supported by Microsoft directly)
Affected platform versions
All
Did you find any workaround?
This is a Compiled Bindings issue. There are the following workarounds:
- Add the
[XamlCompilation(XamlCompilationOptions.Skip)]Attribute to the View class in the .xaml.cs file. - Create a static field/property that exists in your own namespace, reference that from the binding, and have the field redirect to the
Microsoft.Maui.Controls.Binding.DoNothingfield.
<Binding Path="Foo" TargetNullValue="{x:Static views:Binding.DoNothing}" />namespace MyProject.Views
{
public sealed class Binding
{
public static readonly object DoNothing = Microsoft.Maui.Controls.Binding.DoNothing;
}
}
Relevant log output
No response