Petar Tasev
6 months ago
committed by
Julien Lebosquain
No known key found for this signature in database
GPG Key ID: 1833CAD10ACC46FD
2 changed files with
32 additions and
1 deletions
-
src/Avalonia.Controls/ComboBox.cs
-
tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs
|
|
|
@ -85,7 +85,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.
|
|
|
|
@ -236,6 +237,14 @@ namespace Avalonia.Controls |
|
|
|
UpdateFlowDirection(); |
|
|
|
} |
|
|
|
|
|
|
|
protected override void UpdateDataValidation(AvaloniaProperty property, BindingValueType state, Exception? error) |
|
|
|
{ |
|
|
|
base.UpdateDataValidation(property, state, error); |
|
|
|
|
|
|
|
if (property == TextProperty) |
|
|
|
DataValidationErrors.SetError(this, error); |
|
|
|
} |
|
|
|
|
|
|
|
protected internal override Control CreateContainerForItemOverride(object? item, int index, object? recycleKey) |
|
|
|
{ |
|
|
|
return new ComboBoxItem(); |
|
|
|
|
|
|
|
@ -391,6 +391,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() |
|
|
|
{ |
|
|
|
|