From 6dec211beab5ff1b2f764bc0b967b6ae455bd0bf Mon Sep 17 00:00:00 2001 From: Petar Tasev Date: Wed, 25 Mar 2026 10:29:25 -0700 Subject: [PATCH] Fix ComboBox not showing Text property validation (#20978) --- src/Avalonia.Controls/ComboBox.cs | 3 ++- .../ComboBoxTests.cs | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/ComboBox.cs b/src/Avalonia.Controls/ComboBox.cs index eb1eab5856..1571eb9fe7 100644 --- a/src/Avalonia.Controls/ComboBox.cs +++ b/src/Avalonia.Controls/ComboBox.cs @@ -86,7 +86,8 @@ namespace Avalonia.Controls /// Defines the property /// public static readonly StyledProperty TextProperty = - TextBlock.TextProperty.AddOwner(new(string.Empty, BindingMode.TwoWay)); + TextBlock.TextProperty.AddOwner(new(string.Empty, BindingMode.TwoWay, + enableDataValidation: true)); /// /// Defines the property. diff --git a/tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs b/tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs index ca1fa66d91..578484557f 100644 --- a/tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs +++ b/tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs @@ -392,6 +392,28 @@ namespace Avalonia.Controls.UnitTests } + [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(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() {