Skip to content

x:Static in conjunction with XamlCompilation results in XFC0101 compile time error. #11833

@bakerhillpins

Description

@bakerhillpins

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

  1. Create a new MAUI app
  2. 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>
  1. 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:

  1. Add the [XamlCompilation(XamlCompilationOptions.Skip)] Attribute to the View class in the .xaml.cs file.
  2. 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.DoNothing field.
<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

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions