2012-03-29 5 views
3

私はDataGridに教授用のクラスのリストを表示しています。私がしたいのは、教授がDataGridの行をクリックし、そのクラスにいる生徒を表示できるようにすることです。DataGridの行をクリックすると詳細が表示されます

これはWPFでも可能ですか? DataGrid内

+0

基本情報はhttps://www.wpftutorial.net/DataGrid.htmlのトピック「行の詳細」の下にあります。 – hypnos

答えて

1

は、次のセクションを追加:あなたは、テーブル内のインライン詳細を表示したい場合は

<DataGrid.RowDetailsTemplate> 
    <DataTemplate> 
     <DataGrid ItemsSource="{Binding students}"> 
     </DataGrid> 
    </DataTemplate> 
</DataGrid.RowDetailsTemplate> 
0

を、@AnsonWoodyは答えを書きました。外側の詳細を別のコントロールに表示する場合は、DateGridまたはCurrentItemSelectedItemCollectionViewSourceに設定してください。

あなたのDataContextはClassesWithStudentsの項目が含まれており、各項目は、プロパティStudentsを持っている、あなたは次の操作を実行したと仮定すると:

<StackPanel x:Name="panel1"> 
    <StackPanel.Resources> 
     <CollectionViewSource x:Key="classesCollection" Source="{Binding ClassesWithStudents}"/> 
    </StackPanel.Resources> 
    <DataGrid x:Name="dg1" ItemsSource="{Binding Source={StaticResource classesCollection}}"> 
    </DataGrid> 
    <!-- Bind current item with path=/ --> 
    <ContentControl Content="{Binding Source={StaticResource classesCollection},Path=/Students}"/> 
    <!-- Bind selected item --> 
    <ContentControl Content="{Binding ElementName=dg1,Path=SelectedItem.Students}"/> 
</StackPanel> 

ContentControl ofcourseのは、唯一のプレースホルダです。 Studentsがコレクションの場合は、<ItemsControl ItemsSource="{Binding Source={StaticResource classesCollection},Path=/Students}"/>のようなものを使用してください。

関連する問題