Repository: AvaloniaUI/Avalonia (2026-03-25T02:06:34Z)

Issue:
Support DataValidation on `ComboBox`'s `TextProperty` when `IsEditable`
### Is your feature request related to a problem? Please describe.

Unlike for example TextBox here: https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Controls/TextBox.cs#L154

ComboBox doesn't `enableDataValidation` in it's property definition: https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Controls/ComboBox.cs#L88

There doesn't appear to be a trivial way to opt-in for this validation without either ending up forcing a different usage pattern, either with an AttachedProperty or derived control, or by using some hack-ish reflection.

### Describe the solution you'd like

Would it make sense for validation to be enabled for this property?

In the case that it doesn't, what would be the rationale behind it?

### Describe alternatives you've considered

_No response_

### Additional context

_No response_


Discussion:

Patch:
diff --git a/src/Avalonia.Controls/ComboBox.cs b/src/Avalonia.Controls/ComboBox.cs
index eb1eab5856a..1571eb9fe76 100644
--- a/src/Avalonia.Controls/ComboBox.cs
+++ b/src/Avalonia.Controls/ComboBox.cs
@@ -86,7 +86,8 @@ public class ComboBox : SelectingItemsControl
         /// Defines the <see cref="Text"/> property
         /// </summary>
         public static readonly StyledProperty<string?> TextProperty =
-            TextBlock.TextProperty.AddOwner<ComboBox>(new(string.Empty, BindingMode.TwoWay));
+            TextBlock.TextProperty.AddOwner<ComboBox>(new(string.Empty, BindingMode.TwoWay,
+                enableDataValidation: true));
 
         /// <summary>
         /// Defines the <see cref="SelectionBoxItemTemplate"/> property.


Test patch:
diff --git a/tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs b/tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs
index ca1fa66d910..578484557f0 100644
--- a/tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs
+++ b/tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs
@@ -392,6 +392,28 @@ public void SelectedItem_Validation()
             
         }
 
+        [Fact]
+        public void Text_Validation()
+        {
+            using (UnitTestApplication.Start(TestServices.MockThreadingInterface))
+            {
+                var target = new ComboBox
+                {
+                    Template = GetTemplate(),
+                };
+
+                target.ApplyTemplate();
+                target.Presenter!.ApplyTemplate();
+                
+                var exception = new System.InvalidCastException("failed validation");
+                var textObservable = new BehaviorSubject<BindingNotification>(new BindingNotification(exception, BindingErrorType.DataValidationError));
+                target.Bind(ComboBox.TextProperty, textObservable);
+
+                Assert.True(DataValidationErrors.GetHasErrors(target));
+                Assert.Equal([exception], DataValidationErrors.GetErrors(target));
+            }
+        }
+
         [Fact]
         public void Close_Window_On_Alt_F4_When_ComboBox_Is_Focus()
         {