Browse Source

Enable Copy and Cut in ContextMenu for AutoCompleteBox (#19087)

Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
release/11.3.4
yoyo 6 months ago
committed by Julien Lebosquain
parent
commit
64a2a8a88e
  1. 23
      src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.Properties.cs
  2. 5
      src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs
  3. 1
      src/Avalonia.Themes.Fluent/Controls/AutoCompleteBox.xaml
  4. 1
      src/Avalonia.Themes.Simple/Controls/AutoCompleteBox.xaml

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

@ -22,7 +22,7 @@ namespace Avalonia.Controls
public static readonly StyledProperty<int> CaretIndexProperty = public static readonly StyledProperty<int> CaretIndexProperty =
TextBox.CaretIndexProperty.AddOwner<AutoCompleteBox>(new( TextBox.CaretIndexProperty.AddOwner<AutoCompleteBox>(new(
defaultValue: 0, defaultValue: 0,
defaultBindingMode:BindingMode.TwoWay)); defaultBindingMode: BindingMode.TwoWay));
public static readonly StyledProperty<string?> WatermarkProperty = public static readonly StyledProperty<string?> WatermarkProperty =
TextBox.WatermarkProperty.AddOwner<AutoCompleteBox>(); TextBox.WatermarkProperty.AddOwner<AutoCompleteBox>();
@ -72,6 +72,12 @@ namespace Avalonia.Controls
AvaloniaProperty.Register<AutoCompleteBox, IDataTemplate>( AvaloniaProperty.Register<AutoCompleteBox, IDataTemplate>(
nameof(ItemTemplate)); nameof(ItemTemplate));
/// <summary>
/// Defines the <see cref="ClearSelectionOnLostFocus"/> property
/// </summary>
public static readonly StyledProperty<bool> ClearSelectionOnLostFocusProperty =
TextBox.ClearSelectionOnLostFocusProperty.AddOwner<AutoCompleteBox>();
/// <summary> /// <summary>
/// Identifies the <see cref="IsDropDownOpen" /> property. /// Identifies the <see cref="IsDropDownOpen" /> property.
/// </summary> /// </summary>
@ -295,6 +301,15 @@ namespace Avalonia.Controls
set => SetValue(IsDropDownOpenProperty, value); set => SetValue(IsDropDownOpenProperty, value);
} }
/// <summary>
/// Gets or sets a value that determines whether the <see cref="AutoCompleteBox"/> clears its selection after it loses focus.
/// </summary>
public bool ClearSelectionOnLostFocus
{
get => GetValue(ClearSelectionOnLostFocusProperty);
set => SetValue(ClearSelectionOnLostFocusProperty, value);
}
/// <summary> /// <summary>
/// Gets or sets the <see cref="T:Avalonia.Data.Binding" /> that /// Gets or sets the <see cref="T:Avalonia.Data.Binding" /> that
/// is used to get the values for display in the text portion of /// is used to get the values for display in the text portion of
@ -484,7 +499,7 @@ namespace Avalonia.Controls
get => GetValue(ItemsSourceProperty); get => GetValue(ItemsSourceProperty);
set => SetValue(ItemsSourceProperty, value); set => SetValue(ItemsSourceProperty, value);
} }
/// <summary> /// <summary>
/// Gets or sets the maximum number of characters that the <see cref="AutoCompleteBox"/> can accept. /// 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. /// This constraint only applies for manually entered (user-inputted) text.
@ -494,7 +509,7 @@ namespace Avalonia.Controls
get => GetValue(MaxLengthProperty); get => GetValue(MaxLengthProperty);
set => SetValue(MaxLengthProperty, value); set => SetValue(MaxLengthProperty, value);
} }
/// <summary> /// <summary>
/// Gets or sets custom content that is positioned on the left side of the text layout box /// Gets or sets custom content that is positioned on the left side of the text layout box
/// </summary> /// </summary>
@ -511,6 +526,6 @@ namespace Avalonia.Controls
{ {
get => GetValue(InnerRightContentProperty); get => GetValue(InnerRightContentProperty);
set => SetValue(InnerRightContentProperty, value); set => SetValue(InnerRightContentProperty, value);
} }
} }
} }

5
src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs

@ -813,7 +813,10 @@ namespace Avalonia.Controls
_userCalledPopulate = false; _userCalledPopulate = false;
if (ContextMenu is not { IsOpen: true }) var textBoxContextMenuIsOpen = TextBox?.ContextFlyout?.IsOpen == true || TextBox?.ContextMenu?.IsOpen == true;
var contextMenuIsOpen = ContextFlyout?.IsOpen == true || ContextMenu?.IsOpen == true;
if (!textBoxContextMenuIsOpen && !contextMenuIsOpen && ClearSelectionOnLostFocus)
{ {
ClearTextBoxSelection(); ClearTextBoxSelection();
} }

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

@ -42,6 +42,7 @@
BorderThickness="{TemplateBinding BorderThickness}" BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}" CornerRadius="{TemplateBinding CornerRadius}"
CaretIndex="{TemplateBinding CaretIndex, Mode=TwoWay}" CaretIndex="{TemplateBinding CaretIndex, Mode=TwoWay}"
ClearSelectionOnLostFocus="{TemplateBinding ClearSelectionOnLostFocus}"
Padding="{TemplateBinding Padding}" Padding="{TemplateBinding Padding}"
Margin="0" Margin="0"
DataValidationErrors.Errors="{TemplateBinding (DataValidationErrors.Errors)}" DataValidationErrors.Errors="{TemplateBinding (DataValidationErrors.Errors)}"

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

@ -17,6 +17,7 @@
BorderThickness="{TemplateBinding BorderThickness}" BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}" CornerRadius="{TemplateBinding CornerRadius}"
CaretIndex="{TemplateBinding CaretIndex, Mode=TwoWay}" CaretIndex="{TemplateBinding CaretIndex, Mode=TwoWay}"
ClearSelectionOnLostFocus="{TemplateBinding ClearSelectionOnLostFocus}"
DataValidationErrors.Errors="{TemplateBinding (DataValidationErrors.Errors)}" DataValidationErrors.Errors="{TemplateBinding (DataValidationErrors.Errors)}"
Watermark="{TemplateBinding Watermark}" Watermark="{TemplateBinding Watermark}"
MaxLength="{TemplateBinding MaxLength}" MaxLength="{TemplateBinding MaxLength}"

Loading…
Cancel
Save