powered by simpleCommunicator - 2.0.51     © 2025 Programmizd 02
Форумы / WPF, Silverlight [игнор отключен] [закрыт для гостей] / HierarchicalDataTemplate шаблон.
3 сообщений из 3, страница 1 из 1
HierarchicalDataTemplate шаблон.
    #37704737
lol2
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Доброго всем дня.
Есть элемент TreeView:
Код: xml
1.
2.
 <sdk:TreeView Height="231" HorizontalAlignment="Left" Margin="12,12,0,0" Name="treeView1" VerticalAlignment="Top" Width="376" ItemTemplate="{StaticResource Root}" >
</sdk:TreeView>



Вот описание шаблона HierarchicalDataTemplate:
Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
 <UserControl.Resources>
        
        <sdk:HierarchicalDataTemplate x:Key="ChildTemplate" ItemsSource="{Binding Path=Collection}">
            <TextBlock FontStyle="Italic" Text="{Binding}" />
        </sdk:HierarchicalDataTemplate>
        
        <sdk:HierarchicalDataTemplate x:Key="NameTemplate" ItemsSource="{Binding Path=Title}" ItemTemplate="{StaticResource ChildTemplate}">
            <TextBlock Text="{Binding}" FontWeight="Bold" />
        </sdk:HierarchicalDataTemplate>
        
        
    </UserControl.Resources>



Коллекция к которой привязываемся:
Код: c#
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
List<AbstractNode> node = new List<AbstractNode>();

treeView1.ItemsSource = this.node;

у класса AbstractNode есть 2 свойства 

public List<string> Value
        {
            get { return this.value; }
        }


public string NodeName
        {
            get { return this.nodeName; }
        }

вот к ним мы и привязываемся



В результате выводятся только значения
Код: c#
1.
node.NodeName

при нажатии по элемнтам в дереве ничего не происходит.

Надесь есть люди кто знает. Жду ответа. Если что пишите я буду тут сидеть ждать ))))
...
Рейтинг: 0 / 0
HierarchicalDataTemplate шаблон.
    #37705062
enigmatic
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
lol2,
xaml
Код: c#
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
<UserControl x:Class="SilverlightApplication3___hierarchical.MainPage"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
             mc:Ignorable="d"
             d:DesignHeight="300"
             d:DesignWidth="400">

    <Grid x:Name="LayoutRoot"
          Background="White">
        <sdk:TreeView x:Name="treeView">
            <sdk:TreeView.ItemTemplate>
                <sdk:HierarchicalDataTemplate ItemsSource="{Binding Items}">
                    <TextBlock Text="{Binding Name}" />
                </sdk:HierarchicalDataTemplate>
            </sdk:TreeView.ItemTemplate>
        </sdk:TreeView>
    </Grid>
</UserControl>

cs
Код: c#
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.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightApplication3___hierarchical {
    public partial class MainPage : UserControl {
        public MainPage() {
            InitializeComponent();

            this.treeView.ItemsSource = new List<DataItem> { 
                new DataItem {Name = "1", Items = new List<DataItem>{
                    new DataItem {Name = "1.1", Items = new List<DataItem> {
                        new DataItem {Name = "1.1.1"}
                    }
                }},
            }};
        }
    }

    public class DataItem {
        public string Name { get; set; }
        public IEnumerable<DataItem> Items { get; set; }

        public DataItem() {
            this.Items = new List<DataItem>();
        }
    }
}

...
Рейтинг: 0 / 0
HierarchicalDataTemplate шаблон.
    #37705181
lol2
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Большое спасибо. Приду домой гляну ))) Ещё раз спс.
...
Рейтинг: 0 / 0
3 сообщений из 3, страница 1 из 1
Форумы / WPF, Silverlight [игнор отключен] [закрыт для гостей] / HierarchicalDataTemplate шаблон.
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


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