Browse Source

feat(AutoCompleteBox): Added MaxLength (#14592)

* feat(AutoCompleteBox): Added MaxLength

* fix: Address review
pull/14621/head
workgroupengineering 2 years ago
committed by GitHub
parent
commit
72fb4102d6
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 17
      src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.Properties.cs
  2. 4
      src/Avalonia.Themes.Fluent/Controls/AutoCompleteBox.xaml
  3. 4
      src/Avalonia.Themes.Simple/Controls/AutoCompleteBox.xaml

17
src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.Properties.cs

@ -167,6 +167,12 @@ namespace Avalonia.Controls
AvaloniaProperty.Register<AutoCompleteBox, Func<string?, CancellationToken, Task<IEnumerable<object>>>?>(
nameof(AsyncPopulator));
/// <summary>
/// Defines the <see cref="MaxLength"/> property
/// </summary>
public static readonly StyledProperty<int> MaxLengthProperty =
TextBox.MaxLengthProperty.AddOwner<AutoCompleteBox>();
/// <summary>
/// Gets or sets the caret index
/// </summary>
@ -466,5 +472,16 @@ namespace Avalonia.Controls
get => GetValue(ItemsSourceProperty);
set => SetValue(ItemsSourceProperty, value);
}
/// <summary>
/// Gets or sets the maximum number of characters that the <see cref="AutoCompleteBox"/> can accept.
/// This constraint only applies for manually entered (user-inputted) text.
/// </summary>
public int MaxLength
{
get => GetValue(MaxLengthProperty);
set => SetValue(MaxLengthProperty, value);
}
}
}

4
src/Avalonia.Themes.Fluent/Controls/AutoCompleteBox.xaml

@ -44,7 +44,9 @@
CaretIndex="{TemplateBinding CaretIndex, Mode=TwoWay}"
Padding="{TemplateBinding Padding}"
Margin="0"
DataValidationErrors.Errors="{TemplateBinding (DataValidationErrors.Errors)}" />
DataValidationErrors.Errors="{TemplateBinding (DataValidationErrors.Errors)}"
MaxLength="{TemplateBinding MaxLength}"
/>
<Popup Name="PART_Popup"
WindowManagerAddShadowHint="False"
MinWidth="{Binding Bounds.Width, RelativeSource={RelativeSource TemplatedParent}}"

4
src/Avalonia.Themes.Simple/Controls/AutoCompleteBox.xaml

@ -18,7 +18,9 @@
CornerRadius="{TemplateBinding CornerRadius}"
CaretIndex="{TemplateBinding CaretIndex, Mode=TwoWay}"
DataValidationErrors.Errors="{TemplateBinding (DataValidationErrors.Errors)}"
Watermark="{TemplateBinding Watermark}" />
Watermark="{TemplateBinding Watermark}"
MaxLength="{TemplateBinding MaxLength}"
/>
<Popup Name="PART_Popup"
MinWidth="{Binding Bounds.Width, RelativeSource={RelativeSource TemplatedParent}}"

Loading…
Cancel
Save