예제 #1
0
        /// <summary>
        /// This method reimplements DoSearch from <see cref="TextSearch"/>.
        /// </summary>
        /// <param name="textSearch"></param>
        /// <param name="nextChar"></param>
        private void DoSearch(TextSearchWrapper textSearch, string nextChar)
        {
            bool           lookForFallbackMatchToo = false;
            int            startItemIndex          = 0;
            ItemCollection items = Items;

            if (textSearch.IsActive)
            {
                startItemIndex = textSearch.MatchedItemIndex;
            }
            if (textSearch._charsEntered.Count > 0 && string.Compare(textSearch._charsEntered[textSearch._charsEntered.Count - 1], nextChar, true, TextSearchWrapper.GetCulture(this)) == 0)
            {
                lookForFallbackMatchToo = true;
            }
            string primaryTextPath = TextSearchWrapper.GetPrimaryTextPath(this);
            bool   wasNewCharUsed  = false;
            int    matchingPrefix  = TextSearchWrapper.FindMatchingPrefix(this, primaryTextPath, textSearch.Prefix, nextChar, startItemIndex, lookForFallbackMatchToo, ref wasNewCharUsed);

            if (matchingPrefix != -1)
            {
                if (!textSearch.IsActive || matchingPrefix != startItemIndex)
                {
                    if (SelectedItem != items[matchingPrefix])
                    {
                        SelectedItem = items[matchingPrefix];
                        BringItemIntoView(SelectedItem);
                        UpdateLayout();
                        var container = GetContainerFromItem(SelectedItem) as DataRow;
                        if (container != null)
                        {
                            var cellToFocus = container.FindVisualChildrenOfType <DataCell>().FirstOrDefault(x => x.Focusable);
                            if (cellToFocus != null)
                            {
                                Keyboard.Focus(cellToFocus);
                            }
                        }
                    }
                    textSearch.MatchedItemIndex = matchingPrefix;
                }
                if (wasNewCharUsed)
                {
                    textSearch.AddCharToPrefix(nextChar);
                }
                if (!textSearch.IsActive)
                {
                    textSearch.IsActive = true;
                }
            }
            if (textSearch.IsActive)
            {
                textSearch.ResetTimeout();
            }
        }
예제 #2
0
        /// <inheritdoc/>
        protected override void OnTextInput(TextCompositionEventArgs e)
        {
            base.OnTextInput(e);
            if (string.IsNullOrEmpty(e.Text) || !IsTextSearchEnabled || !Equals(e.Source, this) && !Equals(ItemsControlFromItemContainer(e.Source as DependencyObject), this))
            {
                return;
            }

            var textSearch = TextSearchWrapper.EnsureInstance(this);

            if (textSearch == null)
            {
                return;
            }

            DoSearch(textSearch, e.Text);
            e.Handled = true;
        }