diff --git a/src/Avalonia.Controls/AutoCompleteBox.cs b/src/Avalonia.Controls/AutoCompleteBox.cs index 3e4f47ec8a..c62ad3030e 100644 --- a/src/Avalonia.Controls/AutoCompleteBox.cs +++ b/src/Avalonia.Controls/AutoCompleteBox.cs @@ -467,10 +467,11 @@ namespace Avalonia.Controls /// /// dependency property. public static readonly DirectProperty TextProperty = - AvaloniaProperty.RegisterDirect( - nameof(Text), + TextBlock.TextProperty.AddOwnerWithDataValidation( o => o.Text, - (o, v) => o.Text = v); + (o, v) => o.Text = v, + defaultBindingMode: BindingMode.TwoWay, + enableDataValidation: true); /// /// Identifies the @@ -1242,6 +1243,20 @@ namespace Avalonia.Controls base.OnApplyTemplate(e); } + + /// + /// Called to update the validation state for properties for which data validation is + /// enabled. + /// + /// The property. + /// The new binding value for the property. + protected override void UpdateDataValidation(AvaloniaProperty property, BindingValue value) + { + if (property == TextProperty) + { + DataValidationErrors.SetError(this, value.Error); + } + } /// /// Provides handling for the