Exemplo n.º 1
0
        public static void ExpandAndSelectXamTree(this XamDataTree tree, Stack <FreeHierarchyTypeTreeItem> chain, bool isExpandLast
                                                  , bool isSelect = true)
        {
            tree.SelectionSettings.SelectedNodes.Clear();
            Action <XamDataTreeNodesCollection> expandAndSelect = null;

            expandAndSelect = delegate(XamDataTreeNodesCollection list)
            {
                var item = chain.Pop();
                var find = list.FirstOrDefault(n => (n.Data as FreeHierarchyTypeTreeItem).FreeHierTree_ID == item.FreeHierTree_ID);
                if (find == null)
                {
                    return;
                }
                if (chain.Count == 0)
                {
                    if (isExpandLast)
                    {
                        find.IsExpanded = true;
                    }
                    if (isSelect)
                    {
                        find.IsSelected = true;
                    }
                    tree.SelectionSettings.SelectedNodes.Add(find);
                    tree.ScrollNodeIntoView(find);
                    //tree.BringIntoView();
                }
                else
                {
                    find.IsExpanded = true;
                    expandAndSelect(find.Nodes);
                }
            };
            expandAndSelect(tree.Nodes);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Разворачиваем объект в дереве с подгрузкой узлов
        /// </summary>
        /// <param name="tree"></param>
        /// <param name="chain"></param>
        /// <param name="isExpandLast"></param>
        /// <param name="isSelect"></param>
        /// <param name="afterFound">Действие после нахождения нужного элемента</param>
        public static void ExpandAndSelectXamTreeAsync(this XamDataTree tree, ConcurrentStack <object> chain, bool isExpandLast
                                                       , bool isSelect = true, Action <XamDataTreeNode> afterFound = null)
        {
            tree.SelectionSettings.SelectedNodes.Clear();
            Action <XamDataTreeNodesCollection> expandAndSelect = null;

            //var isFirst = true;

            //CancellationTokenSource tokenSource = null;

            expandAndSelect = delegate(XamDataTreeNodesCollection list)
            {
                object item;
                if (!chain.TryPop(out item))
                {
                    //if (tokenSource != null) tokenSource.Cancel();
                    //WaitPanel.Hide<object>(tree, null, null);

                    return;
                }

                var find = list.FirstOrDefault(n => n.Data.Equals(item));
                if (find == null)
                {
                    //if (tokenSource != null) tokenSource.Cancel();
                    //WaitPanel.Hide<object>(tree, null, null);

                    return;
                }

                if (chain.Count == 0)
                {
                    try
                    {
                        //if (isSelect)
                        {
                            tree.SelectionSettings.SelectedNodes.Add(find);
                            find.IsSelected = true;
                        }

                        if (isExpandLast)
                        {
                            find.IsExpanded = true;
                        }

                        tree.ScrollNodeIntoView(find);


                        FindBar.MoveSelectedNodeIntoCenter(tree);
                    }
                    finally
                    {
                        if (afterFound != null)
                        {
                            afterFound(find);
                        }
                        //if (tokenSource != null) tokenSource.Cancel();
                        //WaitPanel.Hide<object>(tree, null, null);
                    }
                    //}), DispatcherPriority.Send);

                    //tree.BringIntoView();
                }
                else
                {
                    find.IsExpanded = true;
                    expandAndSelect(find.Nodes);


                    //tree.Dispatcher.BeginInvoke((Action)(() =>
                    //{
                    //    expandAndSelect(find.Nodes);
                    //}), DispatcherPriority.Send);
                }
            };

            expandAndSelect(tree.Nodes);
        }