2013-07-08 2 views
0

Person, Address, Dependents 및 Awards에 대한 정보를 볼 수 있도록 DataGrid에 Person 개체 컬렉션을 표시하는 방법입니다.WPF의 중첩 데이터 표시

public class Person 
{ 
     public int PersonId { get; set; } 
     public string FirstName { get; set; } 
     public string LastName { get; set; } 
     public int Age { get; set; } 
     public Address Address { get; set; } 
     public IList<Dependent> Dependents { get; set; } 
     public IList<Award> Awards { get; set; } 
} 

public class Address 
{ 
     public string City { get; set; } 
     public string State { get; set; } 
     public string Country { get; set; } 
} 

public class Dependent 
{ 
     public string DependentName { get; set; } 
     public int DependentAge { get; set; } 
} 

public class Award 
{ 
     public string AwardName { get; set; } 
     public DateTime AwardDate { get; set; } 
} 
+0

당신은 무엇을하려고 않았다

세 번째 옵션은 선택된 행의 세부 사항을 표시하기위한 몇 가지 컨트롤을 사용하는 것입니다? – makc

+0

나는 시도/시도 HierarchicalDataTemplate, 아직 성공. – Brij

답변

1

하나의 옵션은 DataGridTemplateColumn을 사용하는 것입니다

<DataGrid ItemsSource="{Binding MyItems}"> 
    <DataGrid.Columns> 
     <DataGridTemplateColumn> 
      <DataGridTemplateColumn.CellTemplate> 
       <DataTemplate> 
        <!-- template for Address, Dependent or Awards types --> 
       </DataTemplate> 
      </DataGridTemplateColumn.CellTemplate> 
     </DataGridTemplateColumn> 
    </DataGrid.Columns> 
</DataGrid> 

두 번째 옵션은 row details을 사용하는 것입니다.

<DataGrid x:Name="myGrid" ItemsSource="{Binding MyItems}"> 
    <!-- The rest of grid here --> 
</DataGrid> 

<ContentControl Content="{Binding SelectedItem, ElementName=myGrid}"> 
    <ContentControl.ContentTemplate> 
     <DataTemplate> 
      <!-- The template for person's details --> 
     </DataTemplate> 
    </ContentControl.ContentTemplate> 
</ContentControl>