リストビューと検索テキストボックスがあります。テキストボックスに文字または記号を入力すると、入力したテキストがリストボックスの項目と一致します。一致するものがあれば、一致した項目が強調表示されます。その時点で、リストビューから一致しないアイテムを削除したいと思います。一致したアイテムのみがリストビューに残ります。それを解決するために私に何を勧めますか?私の他のコードは以下です。
 private void TxtSearch_PreviewKeyUp(object sender, System.Windows.Input.KeyEventArgs e)
 {
        ListControl lc = getactivListview();
        FindListViewItem(lc);
 }
 private void FindListViewItem(DependencyObject obj)
    {
        for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
        {
            ListViewItem lv = obj as ListViewItem;
            if (lv != null)
            {
                HighlightText(lv);
            }
            FindListViewItem(VisualTreeHelper.GetChild(obj as DependencyObject, i));
        }
    }
    private void HighlightText(Object itx)
    {
        if (itx != null)
        {
            if (itx is TextBlock)
            {
                Regex regex = new Regex("(" +TxtSearch.Text + ")", RegexOptions.IgnoreCase);
                TextBlock tb = itx as TextBlock;
                if (TxtSearch.Text.Length == 0)
                {
                    string str = tb.Text;
                    tb.Inlines.Clear();
                    tb.Inlines.Add(str);
                    return;
                }
                string[] substrings = regex.Split(tb.Text);
                tb.Inlines.Clear();
                foreach (var item in substrings)
                {
                    if (regex.Match(item).Success)
                    {
                        Run runx = new Run(item);
                        runx.Background = Brushes.Lime;
                        tb.Inlines.Add(runx);
                        if (tb.IsMouseOver)
                        {
                            tb.IsEnabled = false;
                        }
                    }
                    else
                    {
                        tb.Inlines.Add(item);
                        tb.IsEnabled = false;
                    }
                }
                return;
            }
            else
            {
                for (int i = 0; i < VisualTreeHelper.GetChildrenCount(itx as DependencyObject); i++)
                {
                    HighlightText(VisualTreeHelper.GetChild(itx as DependencyObject, i));
                }
            }
        }
    }