Ver Fonte

Merge branch 'master' into bugfix/double_precision

Dariusz Komosiński há 5 anos atrás
pai
commit
e35e7035f0
1 ficheiros alterados com 18 adições e 3 exclusões
  1. 18 3
      src/Avalonia.Controls/AutoCompleteBox.cs

+ 18 - 3
src/Avalonia.Controls/AutoCompleteBox.cs

@@ -468,10 +468,11 @@ namespace Avalonia.Controls
         /// <see cref="P:Avalonia.Controls.AutoCompleteBox.Text" />
         /// dependency property.</value>
         public static readonly DirectProperty<AutoCompleteBox, string> TextProperty =
-            AvaloniaProperty.RegisterDirect<AutoCompleteBox, string>(
-                nameof(Text),
+            TextBlock.TextProperty.AddOwnerWithDataValidation<AutoCompleteBox>(
                 o => o.Text,
-                (o, v) => o.Text = v);
+                (o, v) => o.Text = v,
+                defaultBindingMode: BindingMode.TwoWay,
+                enableDataValidation: true);
 
         /// <summary>
         /// Identifies the
@@ -1244,6 +1245,20 @@ namespace Avalonia.Controls
 
             base.OnApplyTemplate(e);
         }
+        
+        /// <summary>
+        /// Called to update the validation state for properties for which data validation is
+        /// enabled.
+        /// </summary>
+        /// <param name="property">The property.</param>
+        /// <param name="value">The new binding value for the property.</param>
+        protected override void UpdateDataValidation<T>(AvaloniaProperty<T> property, BindingValue<T> value)
+        {
+            if (property == TextProperty)
+            {
+                DataValidationErrors.SetError(this, value.Error);
+            }
+        }
 
         /// <summary>
         /// Provides handling for the