|
|
@ -107,16 +107,26 @@ namespace Avalonia.Controls |
|
|
private AvaloniaList<object>? _view; |
|
|
private AvaloniaList<object>? _view; |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets or sets a value to ignore a number of pending change handlers.
|
|
|
/// Gets or sets a counter that tracks how many pending Text property change
|
|
|
/// The value is decremented after each use. This is used to reset the
|
|
|
/// notifications should be ignored. This is used when the Text property is set
|
|
|
/// value of properties without performing any of the actions in their
|
|
|
/// programmatically and we want to suppress the corresponding change handlers.
|
|
|
/// change handlers.
|
|
|
/// The counter is decremented after each ignored notification.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <remarks>The int is important as a value because the TextBox
|
|
|
/// <remarks>
|
|
|
/// TextChanged event does not immediately fire, and this will allow for
|
|
|
/// The counter is important because the TextBox TextChanged event does not fire
|
|
|
/// nested property changes to be ignored.</remarks>
|
|
|
/// immediately; using a counter allows nested property changes to be ignored safely.
|
|
|
|
|
|
/// </remarks>
|
|
|
private int _ignoreTextPropertyChange; |
|
|
private int _ignoreTextPropertyChange; |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets a counter that tracks how many pending TextBox TextChanged
|
|
|
|
|
|
/// events should be ignored. This is distinct from <see cref="_ignoreTextPropertyChange"/>
|
|
|
|
|
|
/// and is used when the TextBox's TextChanged event needs to be suppressed
|
|
|
|
|
|
/// (e.g., during programmatic updates to the text box content).
|
|
|
|
|
|
/// The counter is decremented after each ignored event.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private int _ignoreTextBoxTextChange; |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets or sets a value indicating whether to ignore calling a pending
|
|
|
/// Gets or sets a value indicating whether to ignore calling a pending
|
|
|
/// change handlers.
|
|
|
/// change handlers.
|
|
|
@ -371,6 +381,12 @@ namespace Avalonia.Controls |
|
|
/// <param name="e">Event arguments.</param>
|
|
|
/// <param name="e">Event arguments.</param>
|
|
|
private void OnTextPropertyChanged(AvaloniaPropertyChangedEventArgs e) |
|
|
private void OnTextPropertyChanged(AvaloniaPropertyChangedEventArgs e) |
|
|
{ |
|
|
{ |
|
|
|
|
|
if (_ignoreTextPropertyChange > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
_ignoreTextPropertyChange--; |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
TextUpdated((string?)e.NewValue, false); |
|
|
TextUpdated((string?)e.NewValue, false); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -1226,6 +1242,12 @@ namespace Avalonia.Controls |
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
private void OnTextBoxTextChanged() |
|
|
private void OnTextBoxTextChanged() |
|
|
{ |
|
|
{ |
|
|
|
|
|
if (_ignoreTextBoxTextChange > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
_ignoreTextBoxTextChange--; |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//Uses Dispatcher.Post to allow the TextBox selection to update before processing
|
|
|
//Uses Dispatcher.Post to allow the TextBox selection to update before processing
|
|
|
Dispatcher.UIThread.Post(() => |
|
|
Dispatcher.UIThread.Post(() => |
|
|
{ |
|
|
{ |
|
|
@ -1270,7 +1292,7 @@ namespace Avalonia.Controls |
|
|
// Update the TextBox's Text dependency property
|
|
|
// Update the TextBox's Text dependency property
|
|
|
if ((userInitiated == null || userInitiated == false) && TextBox != null && TextBox.Text != value) |
|
|
if ((userInitiated == null || userInitiated == false) && TextBox != null && TextBox.Text != value) |
|
|
{ |
|
|
{ |
|
|
_ignoreTextPropertyChange++; |
|
|
_ignoreTextBoxTextChange++; |
|
|
TextBox.Text = value ?? string.Empty; |
|
|
TextBox.Text = value ?? string.Empty; |
|
|
|
|
|
|
|
|
// Text dependency property value was set, fire event
|
|
|
// Text dependency property value was set, fire event
|
|
|
@ -1296,14 +1318,6 @@ namespace Avalonia.Controls |
|
|
/// TextUpdated method is called from a TextBox event handler.</param>
|
|
|
/// TextUpdated method is called from a TextBox event handler.</param>
|
|
|
private void TextUpdated(string? newText, bool userInitiated) |
|
|
private void TextUpdated(string? newText, bool userInitiated) |
|
|
{ |
|
|
{ |
|
|
// Only process this event if it is coming from someone outside
|
|
|
|
|
|
// setting the Text dependency property directly.
|
|
|
|
|
|
if (_ignoreTextPropertyChange > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
_ignoreTextPropertyChange--; |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (newText == null) |
|
|
if (newText == null) |
|
|
{ |
|
|
{ |
|
|
newText = string.Empty; |
|
|
newText = string.Empty; |
|
|
|