powered by simpleCommunicator - 2.0.59     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / WPF, Silverlight [игнор отключен] [закрыт для гостей] / Как програмно найти, (чтоб выделить) узел дерева если он не корневой?
3 сообщений из 3, страница 1 из 1
Как програмно найти, (чтоб выделить) узел дерева если он не корневой?
    #37059317
karapetyan_a
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Народ как найти узел дерева TreeView в Silverlight если он не корневой, потому как корневой я могу найти так:

Код: plaintext
TreeViewItem tvi = (TreeViewItem)this._treeControl.ItemContainerGenerator.ContainerFromItem(ti);

если же узел вложенный то tvi = null.

С уважением. Ашот.
...
Рейтинг: 0 / 0
Как програмно найти, (чтоб выделить) узел дерева если он не корневой?
    #37060294
JohnSparrow
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
+

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
    public static class TreeViewExtensions
    {
        /// <summary>
        /// Selects an item in a TreeView using a path
        /// </summary>
        /// <param name="treeView">The TreeView to select an item in</param>
        /// <param name="path">The path to the selected item.
        /// Components of the path are separated with Path.DirectorySeparatorChar.
        /// Items in the control are converted by calling the ToString method.</param>
        public static void SetSelectedItem(this TreeView treeView, string path)
        {
            treeView.SetSelectedItem(path, item => item.ToString());
        }

        /// <summary>
        /// Selects an item in a TreeView using a path and a custom conversion method
        /// </summary>
        /// <param name="treeView">The TreeView to select an item in</param>
        /// <param name="path">The path to the selected item.
        /// Components of the path are separated with Path.DirectorySeparatorChar.</param>
        /// <param name="convertMethod">A custom method that converts items in the control to their respective path component</param>
        public static void SetSelectedItem(this TreeView treeView, string path,
            Func<object, string> convertMethod)
        {
            treeView.SetSelectedItem(path, convertMethod, Path.DirectorySeparatorChar);
        }

        /// <summary>
        /// Selects an item in a TreeView using a path and a custom path separator character.
        /// </summary>
        /// <param name="treeView">The TreeView to select an item in</param>
        /// <param name="path">The path to the selected item</param>
        /// <param name="separatorChar">The character that separates path components</param>
        public static void SetSelectedItem(this TreeView treeView, string path,
            char separatorChar)
        {
            treeView.SetSelectedItem(path, item => item.ToString(), separatorChar);
        }

        /// <summary>
        /// Selects an item in a TreeView using a path, a custom conversion method,
        /// and a custom path separator character.
        /// </summary>
        /// <param name="treeView">The TreeView to select an item in</param>
        /// <param name="path">The path to the selected item</param>
        /// <param name="convertMethod">A custom method that converts items in the control to their respective path component</param>
        /// <param name="separatorChar">The character that separates path components</param>
        public static void SetSelectedItem(this TreeView treeView, string path,
            Func<object, string> convertMethod, char separatorChar)
        {
            treeView.SetSelectedItem<string>(
                path.Split(new char[] { separatorChar },
                    StringSplitOptions.RemoveEmptyEntries),
                (x, y) => x == y,
                convertMethod
            );
        }

        /// <summary>
        /// Selects an item in a TreeView using a custom item chain
        /// </summary>
        /// <typeparam name="T">The type of the items present in the control and the chain</typeparam>
        /// <param name="treeView">The TreeView to select an item in</param>
        /// <param name="items">The chain of items to walk. The last item in the chain will be selected</param>
        public static void SetSelectedItem<T>(this TreeView treeView, IEnumerable<T> items)
            where T : class
        {
            // Use a default compare method with the '==' operator
            treeView.SetSelectedItem<T>(items,
                (x, y) => x == y
            );
        }

        /// <summary>
        /// Selects an item in a TreeView using a custom item chain and item comparison method
        /// </summary>
        /// <typeparam name="T">The type of the items present in the control and the chain</typeparam>
        /// <param name="treeView">The TreeView to select an item in</param>
        /// <param name="items">The chain of items to walk. The last item in the chain will be selected</param>
        /// <param name="compareMethod">The method used to compare items in the control with items in the chain</param>
        public static void SetSelectedItem<T>(this TreeView treeView, IEnumerable<T> items,
            Func<T, T, bool> compareMethod)
        {
            treeView.SetSelectedItem<T>(items, compareMethod, null);
        }

        /// <summary>
        /// Selects an item in a TreeView using a custom item chain, an item comparison method,
        /// and an item conversion method.
        /// </summary>
        /// <typeparam name="T">The type of the items present in the control and the chain</typeparam>
        /// <param name="treeView">The TreeView to select an item in</param>
        /// <param name="items">The chain of items to walk. The last item in the chain will be selected</param>
        /// <param name="compareMethod">The method used to compare items in the control with items in the chain</param>
        /// <param name="convertMethod">The method used to convert items in the control to be compared with items in the chain</param>
        public static void SetSelectedItem<T>(this TreeView treeView, IEnumerable<T> items,
            Func<T, T, bool> compareMethod, Func<object, T> convertMethod)
        {
            // Setup default options for a TreeView
            UIUtility.SetSelectedItem<T>(treeView,
                new SetSelectedInfo<T>()
                {
                    Items = items,
                    CompareMethod = compareMethod,
                    ConvertMethod = convertMethod,
                    OnSelected = delegate(ItemsControl container, SetSelectedInfo<T> info)
                    {
                        var treeItem = (TreeViewItem)container;
                        treeItem.IsSelected = true;
                        treeItem.BringIntoView();
                    },
                    OnNeedMoreItems = delegate(ItemsControl container, SetSelectedInfo<T> info)
                    {
                        ((TreeViewItem)container).IsExpanded = true;
                    }
                }
            );
        }
    }
...
Рейтинг: 0 / 0
Как програмно найти, (чтоб выделить) узел дерева если он не корневой?
    #37061935
karapetyan_a
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
JohnSparrow,

Спасибо, решение как я понимаю отсюдова (codeproject)

.... как я понимаю не все просто, в ВинФормсе можно было использовать MyTree.SelectedItem = MyItem потому как все элементы дерева были уже созданы, здесь же (silverlight/wpf) узлы дерева создаются "по требованию".......... остюда и проблема.........

По любому спасибо, начал понимать проблему......
...
Рейтинг: 0 / 0
3 сообщений из 3, страница 1 из 1
Форумы / WPF, Silverlight [игнор отключен] [закрыт для гостей] / Как програмно найти, (чтоб выделить) узел дерева если он не корневой?
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]