System.Windows.Controls.AutoCompleteBox.TextUpdated C# (CSharp) Méthode

TextUpdated() private méthode

Handle the update of the text for the control from any source, including the TextBox part and the Text dependency property.
private TextUpdated ( string newText, bool userInitiated ) : void
newText string The new text.
userInitiated bool A value indicating whether the update /// is a user-initiated action. This should be a True value when the /// TextUpdated method is called from a TextBox event handler.
Résultat void
        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;
                }
            }
        }