Binding Expression Warnings

These warnings focus on Binding expressions in Xaml code, identifying both syntax problems and misuse of view models.

[XR5001, XR5018, XR5019, XR5022, XR5029] Syntax errors in Binding expression

XamRight checks for some syntax errors in x:Bind and Binding expressions. Warnings are issued if the markups either don’t start with a open brace or don’t end with a close brace. XamRight also ensures all property declarations in a Binding markup are separated by commas and there are no unterminated string literals within the markup. Apart from that, XamRight also checks that the Path property on the Binding expression is not set to a namespace identifier. Left unresolved, these are likely to result in silent failures at runtime.

[XR5007, XR5008, XR5009] Binding to a static,
non-property or private identifier

When using Binding expressions, the Binding Path has to be set to a public, non-static property. XamRight warns if the Path is set to an identifier that is static, private or is not a property.

[XR5010, XR5011, XR5041, XR5083, XR5084] Binding to a property that doesn’t exist

When XamRight detects an attempt to bind to a property that doesn’t exist on BindingContext type in effect for a Binding expression, it will generate one of these warnings. These warnings will include the BindingContext type, as well as additional information where possible, such as a suggested correct property name.

[XR5012] Binding target is not a bindable property

Not all properties of an element in a Xaml file can be set to a Binding markup. The target property that a Binding expression can be applied to has to be backed by a BindableProperty as described in this post – https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/data-binding/basic-bindings. Similarly, when using Binding expressions in UWP and WPF the target property has to be backed by a DependencyProperty:
1. Xamarin BindableProperty
2. UWP DependencyProperty
3. WPF DependencyProperty
XamRight warns if it cannot locate the backing property for properties that are set to a Binding expression.

[XR5016, XR5020, XR5026] Misspelled, repeated or non-existent property in Binding expression

The Binding markup expression contains a number of properties, such as Path, Source, Mode, Converter, etc. Each platform – Xamarin, UWP and WPF has a different set of available properties on the Binding markup. XamRight parses the Binding expression and checks for the usage of any misspelled, repeated or nonexistent properties according to the platform used.

[XR5017] Error in Binding Mode declaration

The BindingMode property on the Binding markup is an enum property that defines whether a Binding value, when updated, can be passed from the source to target property, from the target property to source or both ways. Xamarin, UWP and WPF have their own set of BindingModes when used in a Binding expression. XamRight checks and warns if the BindingMode is set to a non-existent BindingMode enum based on the platform used.

[XR5023, XR5024, XR5025] Syntax errors in Path value and other property value declarations in Binding markup

Both Binding and x:Bind markups have a Path property that can be either explicitly or implicitly declared. XamRight will issue a warning if it cannot parse the path value in a Binding expression. Warnings will also be issued if XamRight is unable to parse the values of any of the other properties defined in the Binding markup.

[XR5040] Target property must be set to a Binding expression

In some contexts, certain properties should be set to a Binding expression, most notably in specific grouped ListView situations. Accordingly, XamRight informs if these properties are not set to a Binding markup.

[XR5076] Cannot use nullable type for Binding value

Certain properties on UI elements do not fully support Binding to a view model property with a nullable type, such as int?. XamRight generates warnings when it detects this situation. The effects of binding to nullable types are typically either:

  • App crash when creating view if the property is null
  • When bound to a property which expects input from the user, for instance Entry.Text (Xamarin.Forms) or TextBox.Text (UWP), the view model property is not updated when the user provides input.

The set of properties varies across platform and platform version. XamRight tracks the platform versions, so it will only warn when it appears the code is likely to be a problem on the specific platform version in use.

Author