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)
{
newText = string.Empty;
}
// The TextBox.TextChanged event was not firing immediately and
// was causing an immediate update, even with wrapping. If there is
// a selection currently, no update should happen.
if(IsTextCompletionEnabled && TextBox != null && TextBox.SelectionLength > 0 && TextBox.SelectionStart != TextBox.Text.Length)
{
return;
}
// Evaluate the conditions needed for completion.
// 1. Minimum prefix length
// 2. If a delay timer is in use, use it
bool populateReady = newText.Length >= MinimumPrefixLength && MinimumPrefixLength >= 0;
_userCalledPopulate = populateReady && userInitiated;
// Update the interface and values only as necessary
UpdateTextValue(newText, userInitiated);
if(populateReady)
{
_ignoreTextSelectionChange = true;
if(_delayTimer != null)
{
_delayTimer.Start();
}
else
{
PopulateDropDown(this, EventArgs.Empty);
}
}
else
{
SearchText = string.Empty;
if(SelectedItem != null)
{
_skipSelectedItemTextUpdate = true;
}
SelectedItem = null;
if(IsDropDownOpen)
{
IsDropDownOpen = false;
}
}
}