좋아, 지금은 알 수 없다. 나는 잠시 동안 구글과 유래를 검색 및 부지의 나는 모습 Class
라는 클래스가있는 HierarchicalDataTemplate
TreeView 용 HierarchicalDataTemplate
사용하는 방법을 예제를보고했습니다 : 나는 보이는 Pupil
라는 클래스가
[Table(Name = "Class")]
public class Class
{
[Column(IsDbGenerated = true, IsPrimaryKey = true)]
public int Id { get; private set; }
[Column]
public string ClassName { get; set; }
}
과 같은 :
[Table(Name = "Pupil")]
public class Pupil
{
[Column(IsPrimaryKey = true, IsDbGenerated = true)]
public int Id { get; private set; }
public Name Name
{
get { return this.nameEntityRef.Entity; }
set
{
this.nameEntityRef.Entity = value;
this.NameId = value.Id;
}
}
public Address Address
{
get { return this.addressEntityRef.Entity; }
set
{
this.addressEntityRef.Entity = value;
this.AddressId = value.Id;
}
}
public Class Class
{
get { return this.classEntityRef.Entity; }
set
{
this.classEntityRef.Entity = value;
this.ClassId = value.Id;
}
}
private EntityRef<Name> nameEntityRef;
private EntityRef<Address> addressEntityRef;
private EntityRef<Class> classEntityRef;
[Column]
internal int AddressId { get; set; }
[Column]
internal int NameId { get; set; }
[Column]
internal int ClassId { get; set; }
}
그리고
0과 같은ClassPupils
라는 클래스를 도입
ClassPupils
은 모든 학생을 수업에 포함해야합니다.
이제 TreeView
을 만들고 싶습니다. 여기에 Pupil
이 모두 나열되어 있습니다. Class
. 그래서 내 ViewModel에 ObservableCollection<ClassPupils>
을 사용합니다. 내보기에서이 컬렉션에 바인딩됩니다. TreeView에 대한 나의보기-코드는 다음과 같습니다
<TreeView Grid.Row="0" Grid.Column="0" Margin="2" ItemsSource="{Binding ClassPupils}">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type model:ClassPupils}" ItemsSource="{Binding Class}">
<Label Content="{Binding Class.ClassName}"/>
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type entity:Pupil}">
<Label Content="{Binding Name.Lastname}"/>
</DataTemplate>
</TreeView.Resources>
</TreeView>
그러나 나는 단지 클래스가 아닌 학생들-성을위한 TreeViewItems를 얻을. 내가 도대체 뭘 잘못하고있는 겁니까?
완벽합니다. 잠시 설명해 주시겠습니까? 이해할 수 있습니까? – Tomtom
답변에 설명이 추가되었습니다. –
완벽. 나는 10 분 안에 당신의 대답을 받아 들일 것입니다 :) – Tomtom