Beispiel #1
0
        private bool Select(TreeViewItem item, object data)
        {
            if (item == null)
            {
                return(false);
            }

            bool          found    = false;
            MatchTreeNode itemData = (MatchTreeNode)item.DataContext;

            if (itemData == data)
            {
                found = true;
            }
            else
            {
                found = false;
            }

            if (found)
            {
                item.IsSelected = true;
                return(true);
            }

            foreach (object c in item.Items) // Not found. Recursion
            {
                //var childData = item.DataContext;
                TreeViewItem childItem = item.ItemContainerGenerator.ContainerFromItem(c) as TreeViewItem;
                //TreeViewItem child = item.ItemContainerGenerator.ContainerFromItem(data) as TreeViewItem;
                bool result = Select(childItem, data);
                if (result == true)
                {
                    return(true);
                }
            }

            return(false);
        }