Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Avalonia.Controls/ComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 22 additions & 0 deletions tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down