When a validation callback of a BindableProperty returns false,
no Exeption is raised as documented here
Example:
public class CustomControl : ContentView
{
public static readonly BindableProperty CustomTextProperty = BindableProperty.Create(
nameof(CustomText),
typeof(string),
typeof(CustomControl),
defaultValue: string.Empty,
validateValue: (bindable, value) =>
{
// This validator returns false for empty strings
// We expect this to throw an ArgumentException, but it doesn't
return !string.IsNullOrEmpty((string)value);
}
);
public string CustomText
{
get => (string)GetValue(CustomTextProperty);
set => SetValue(CustomTextProperty, value);
}
public CustomControl()
{
// Basic layout for demonstration
Content = new Label
{
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
};
CustomText = "some valid text";
// Set up the binding correctly
((Label)Content).SetBinding(Label.TextProperty, new Binding(nameof(CustomText), source: this));
}
}
Description
When a validation callback of a BindableProperty returns false, no Exeption is raised as documented here
Example:
Steps to Reproduce
Link to the reproduction link below
Link to public reproduction project repository
https://github.com/zauberzeug/Maui_BindableProperty_validation
Version with bug
8.0.40 SR5
Is this a regression from previous behavior?
Not sure, did not test other versions, Yes, this used to work in Xamarin.Forms
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android, I was not able test on other platforms
Affected platform versions
iOS 17, Android 13
Did you find any workaround?
Throw an Exeption inside the validation callback.