Browse Source

Fix ComboBox not showing Text property validation (#20978)

pull/20994/head
Petar Tasev 6 months ago
committed by GitHub
parent
commit
6dec211bea
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 3
      src/Avalonia.Controls/ComboBox.cs
  2. 22
      tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs

3
src/Avalonia.Controls/ComboBox.cs

@ -86,7 +86,8 @@ namespace Avalonia.Controls
/// 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.

22
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<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()
{

Loading…
Cancel
Save