Enable Copy and Cut in ContextMenu for AutoCompleteBox (#19087)
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
This commit is contained in:
@@ -22,7 +22,7 @@ namespace Avalonia.Controls
|
||||
public static readonly StyledProperty<int> CaretIndexProperty =
|
||||
TextBox.CaretIndexProperty.AddOwner<AutoCompleteBox>(new(
|
||||
defaultValue: 0,
|
||||
defaultBindingMode:BindingMode.TwoWay));
|
||||
defaultBindingMode: BindingMode.TwoWay));
|
||||
|
||||
public static readonly StyledProperty<string?> WatermarkProperty =
|
||||
TextBox.WatermarkProperty.AddOwner<AutoCompleteBox>();
|
||||
@@ -72,6 +72,12 @@ namespace Avalonia.Controls
|
||||
AvaloniaProperty.Register<AutoCompleteBox, IDataTemplate>(
|
||||
nameof(ItemTemplate));
|
||||
|
||||
/// <summary>
|
||||
/// Defines the <see cref="ClearSelectionOnLostFocus"/> property
|
||||
/// </summary>
|
||||
public static readonly StyledProperty<bool> ClearSelectionOnLostFocusProperty =
|
||||
TextBox.ClearSelectionOnLostFocusProperty.AddOwner<AutoCompleteBox>();
|
||||
|
||||
/// <summary>
|
||||
/// Identifies the <see cref="IsDropDownOpen" /> property.
|
||||
/// </summary>
|
||||
@@ -295,6 +301,15 @@ namespace Avalonia.Controls
|
||||
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>
|
||||
/// Gets or sets the <see cref="T:Avalonia.Data.Binding" /> that
|
||||
/// is used to get the values for display in the text portion of
|
||||
@@ -484,7 +499,7 @@ 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.
|
||||
@@ -494,7 +509,7 @@ namespace Avalonia.Controls
|
||||
get => GetValue(MaxLengthProperty);
|
||||
set => SetValue(MaxLengthProperty, value);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets custom content that is positioned on the left side of the text layout box
|
||||
/// </summary>
|
||||
@@ -511,6 +526,6 @@ namespace Avalonia.Controls
|
||||
{
|
||||
get => GetValue(InnerRightContentProperty);
|
||||
set => SetValue(InnerRightContentProperty, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -813,7 +813,10 @@ namespace Avalonia.Controls
|
||||
|
||||
_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();
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="{TemplateBinding CornerRadius}"
|
||||
CaretIndex="{TemplateBinding CaretIndex, Mode=TwoWay}"
|
||||
ClearSelectionOnLostFocus="{TemplateBinding ClearSelectionOnLostFocus}"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
Margin="0"
|
||||
DataValidationErrors.Errors="{TemplateBinding (DataValidationErrors.Errors)}"
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="{TemplateBinding CornerRadius}"
|
||||
CaretIndex="{TemplateBinding CaretIndex, Mode=TwoWay}"
|
||||
ClearSelectionOnLostFocus="{TemplateBinding ClearSelectionOnLostFocus}"
|
||||
DataValidationErrors.Errors="{TemplateBinding (DataValidationErrors.Errors)}"
|
||||
Watermark="{TemplateBinding Watermark}"
|
||||
MaxLength="{TemplateBinding MaxLength}"
|
||||
|
||||
Reference in New Issue
Block a user