私はDataGrid
に教授用のクラスのリストを表示しています。私がしたいのは、教授がDataGrid
の行をクリックし、そのクラスにいる生徒を表示できるようにすることです。DataGridの行をクリックすると詳細が表示されます
これはWPFでも可能ですか? DataGrid内
私はDataGrid
に教授用のクラスのリストを表示しています。私がしたいのは、教授がDataGrid
の行をクリックし、そのクラスにいる生徒を表示できるようにすることです。DataGridの行をクリックすると詳細が表示されます
これはWPFでも可能ですか? DataGrid内
は、次のセクションを追加:あなたは、テーブル内のインライン詳細を表示したい場合は
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<DataGrid ItemsSource="{Binding students}">
</DataGrid>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
を、@AnsonWoodyは答えを書きました。外側の詳細を別のコントロールに表示する場合は、DateGrid
またはCurrentItem
のSelectedItem
をCollectionViewSource
に設定してください。
あなたの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}"/>
のようなものを使用してください。
基本情報はhttps://www.wpftutorial.net/DataGrid.htmlのトピック「行の詳細」の下にあります。 – hypnos