コード例 #1
0
        private void ClearSearch()
        {
            SearchedItems = new ObservableCollection <TreeViewItemAdv>();
            foreach (Model model in Treeview.ItemsSource)
            {
                TreeViewItemAdv mainitem = Treeview.ItemContainerGenerator.ContainerFromItem(model) as TreeViewItemAdv;

                if (mainitem != null)
                {
                    ApplyInline(mainitem, false);
                }


                foreach (Model level2 in model.Children)
                {
                    TreeViewItemAdv level2item = mainitem.ItemContainerGenerator.ContainerFromItem(level2) as TreeViewItemAdv;
                    if (level2item != null)
                    {
                        ApplyInline(level2item, false);
                    }
                    if (level2item != null)
                    {
                        foreach (Model level3 in level2.Children)
                        {
                            TreeViewItemAdv level3item = level2item.ItemContainerGenerator.ContainerFromItem(level3) as TreeViewItemAdv;
                            if (level3item != null)
                            {
                                ApplyInline(level3item, false);
                            }
                        }
                    }
                }
            }
            Treeview.UpdateLayout();
        }
コード例 #2
0
        private void Search()
        {
            ClearSearch();

            if (!string.IsNullOrEmpty(SearchTextBox.Text))
            {
                string searchText = SearchTextBox.Text;

                foreach (Model model in Treeview.ItemsSource)
                {
                    TreeViewItemAdv mainitem = Treeview.ItemContainerGenerator.ContainerFromItem(model) as TreeViewItemAdv;

                    if (mainitem != null && MatchSearchText(model.Header))
                    {
                        //Function which is used to apply inline to the TextBlock
                        ApplyInline(mainitem, false);
                    }

                    foreach (Model level2 in model.Children)
                    {
                        if (MatchSearchText(level2.Header) || level2.Children.Count > 0)
                        {
                            mainitem.IsExpanded = true;
                            Treeview.UpdateLayout();
                        }
                        TreeViewItemAdv level2item = mainitem.ItemContainerGenerator.ContainerFromItem(level2) as TreeViewItemAdv;

                        if (level2item != null)
                        {
                            ApplyInline(level2item, false);
                        }
                        if (level2item != null)
                        {
                            foreach (Model level3 in level2.Children)
                            {
                                if (MatchSearchText(level3.Header) || level3.Children.Count > 0)
                                {
                                    level2item.IsExpanded = true;
                                    Treeview.UpdateLayout();
                                }
                                TreeViewItemAdv level3item = level2item.ItemContainerGenerator.ContainerFromItem(level3) as TreeViewItemAdv;
                                if (level3item != null)
                                {
                                    ApplyInline(level3item, false);
                                }
                            }
                        }
                    }
                }

                if (SearchedItems != null && SearchedItems.Count > 0)
                {
                    ApplyInline(SearchedItems[0], true);
                    SearchedItems[0].BringIntoView();
                    matchindex = 0;
                }
            }
        }