משיב מוביל
Multi-Level TreeView

שאלה
-
שלום לכולם
אני מחפש דרך להרים TreeView אשר הדירוג בו יהיה 3 רמות ומעלה.
לדוגמא:
1. רשימת משפחות - ObservableCollection<Family> Families (יוצג שם משפחה - Name) - רמה ראשונה
2. רשימת חברי במשפחה - ObservableCollection<Person> Persons (יוצג שם - Name) - רמה שנייה
3. אימייל של אותו חבר במשפחה (יוצג Email) - רמה שלישית
מצאתי את הלינק הזה אך הוא לא הביא לי פתרון:
http://social.msdn.microsoft.com/forums/en-US/wpf/thread/e40e0a8f-7758-4b69-80f6-1c657294d019/
הקוד אשר אני ניסיתי להרכיז בעזרתו הוא:
<
UserControl.Resources>
<DataTemplate x:Key="emailDataTemplate">
<Label Content="{Binding Email}"/>
</DataTemplate>
<HierarchicalDataTemplate x:Key="personsHierarchicalTemplate"
ItemsSource="{Binding Path=Persons}"
ItemTemplate="{StaticResource emailDataTemplate}">
<TextBlock Text="{Binding Name}"></TextBlock>
</HierarchicalDataTemplate>
</UserControl.Resources>
<Grid>
<TreeView ItemsSource="{Binding Families}" ItemTemplate="{StaticResource personsHierarchicalTemplate}">
</TreeView>
</Grid>
יום שלישי 24 יולי 2012 09:54
תשובות
-
בבקשה:
זה ה-xaml
<Window x:Class="WpfApplication3.Window3" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window3" Height="300" Width="300"> <Window.Resources> <DataTemplate x:Key="emailDataTemplate"> <Label Content="{Binding}" /> </DataTemplate> <HierarchicalDataTemplate x:Key="personsHierarchicalTemplate" ItemsSource="{Binding Path=Email}" ItemTemplate="{StaticResource emailDataTemplate}"> <TextBlock Text="{Binding Name}"></TextBlock> </HierarchicalDataTemplate> <HierarchicalDataTemplate x:Key="familyHierarchicalTemplate" ItemsSource="{Binding Path=Persons}" ItemTemplate="{StaticResource personsHierarchicalTemplate}"> <TextBlock Text="{Binding Name}"></TextBlock> </HierarchicalDataTemplate> </Window.Resources> <Grid> <TreeView ItemsSource="{Binding Families}" ItemTemplate="{StaticResource familyHierarchicalTemplate}"> </TreeView> </Grid> </Window>
וזה הcode-behind לטובת הדוגמא:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace WpfApplication3 { /// <summary> /// Interaction logic for Window3.xaml /// </summary> public partial class Window3 : Window { public Window3() { InitializeComponent(); Families = new List<Family>() { new Family { Name="fam", Persons=new List<Person>() { new Person(){ Email=new List<string>(){"asd@asd.com"}, Name="person1"} } } }; DataContext = this; } public List<Family> Families { get; set; } } public class Family { public string Name { get; set; } public List<Person> Persons { get; set; } } public class Person { public string Name { get; set; } public List<string> Email { get; set; } } }
- סומן כתשובה על-ידי Shahar Eldad יום רביעי 25 יולי 2012 09:10
יום שלישי 24 יולי 2012 17:09
כל התגובות
-
בבקשה:
זה ה-xaml
<Window x:Class="WpfApplication3.Window3" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window3" Height="300" Width="300"> <Window.Resources> <DataTemplate x:Key="emailDataTemplate"> <Label Content="{Binding}" /> </DataTemplate> <HierarchicalDataTemplate x:Key="personsHierarchicalTemplate" ItemsSource="{Binding Path=Email}" ItemTemplate="{StaticResource emailDataTemplate}"> <TextBlock Text="{Binding Name}"></TextBlock> </HierarchicalDataTemplate> <HierarchicalDataTemplate x:Key="familyHierarchicalTemplate" ItemsSource="{Binding Path=Persons}" ItemTemplate="{StaticResource personsHierarchicalTemplate}"> <TextBlock Text="{Binding Name}"></TextBlock> </HierarchicalDataTemplate> </Window.Resources> <Grid> <TreeView ItemsSource="{Binding Families}" ItemTemplate="{StaticResource familyHierarchicalTemplate}"> </TreeView> </Grid> </Window>
וזה הcode-behind לטובת הדוגמא:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace WpfApplication3 { /// <summary> /// Interaction logic for Window3.xaml /// </summary> public partial class Window3 : Window { public Window3() { InitializeComponent(); Families = new List<Family>() { new Family { Name="fam", Persons=new List<Person>() { new Person(){ Email=new List<string>(){"asd@asd.com"}, Name="person1"} } } }; DataContext = this; } public List<Family> Families { get; set; } } public class Family { public string Name { get; set; } public List<Person> Persons { get; set; } } public class Person { public string Name { get; set; } public List<string> Email { get; set; } } }
- סומן כתשובה על-ידי Shahar Eldad יום רביעי 25 יולי 2012 09:10
יום שלישי 24 יולי 2012 17:09 -
תודה - עכשיו גם הבנתי את הרעיוןיום רביעי 25 יולי 2012 09:10