我想将Datagrid用作另一个Datagrid的RowDetailsTemplate的内容。它的工作非常完美,但是存在问题,即子Datagrid ColumnDefinition似乎没有任何效果。
这是我的代码:
<toolkit:DataGrid VerticalAlignment="Top" HorizontalAlignment="Stretch"
AutoGenerateColumns="False" ItemsSource="{Binding Hauptgruppen}"
IsReadOnly="False" x:Name="HauptgruppenDataGrid"
CanUserAddRows="False"
SelectionUnit="FullRow"
gridtools:DataGridStyle.SelectAllButtonTemplate="{DynamicResource CisSelectAllButtonTemplate}"
SelectedValuePath="."
CanUserResizeColumns="True"
>
<toolkit:DataGrid.RowDetailsTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="#FF4E5790">
<toolkit:DataGrid VerticalAlignment="Top" HorizontalAlignment="Stretch" Margin="50,5,5,5"
ItemsSource="{Binding ElementName=HauptgruppenDataGrid, Path=SelectedValue.BerechtigteUntergruppen}"
x:Name="UntergruppenDataGrid" IsReadOnly="False"
CanUserAddRows="False"
SelectionUnit="FullRow"
gridtools:DataGridStyle.SelectAllButtonTemplate="{DynamicResource CisSelectAllButtonTemplate}"
SelectedValuePath="."
CanUserResizeColumns="True"
>
<toolkit:DataGrid.RowDetailsTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="#FF4E5790">
<toolkit:DataGrid VerticalAlignment="Top" HorizontalAlignment="Stretch" Margin="50,5,5,5"
ItemsSource="{Binding ElementName=UntergruppenDataGrid, Path=SelectedValue.BerechtigteRisiken}"
x:Name="RisikenDataGrid" IsReadOnly="False"
CanUserAddRows="False"
SelectionUnit="FullRow"
gridtools:DataGridStyle.SelectAllButtonTemplate="{DynamicResource CisSelectAllButtonTemplate}"
SelectedValuePath="."
CanUserResizeColumns="True"
>
<toolkit:DataGrid.RowDetailsTemplate>
<DataTemplate>
<risikoControls:RisikoDetails Risiko="{Binding ElementName=RisikenDataGrid, Path=SelectedValue}" />
</DataTemplate>
</toolkit:DataGrid.RowDetailsTemplate>
<toolkit:DataGrid.Columns>
<toolkit:DataGridTextColumn Binding="{Binding Path=Sortierung}" Header="Sortierung" />
<toolkit:DataGridTextColumn Binding="{Binding Path=RisikoBezeichnung}" Header="Risiko" />
<toolkit:DataGridTextColumn Binding="{Binding Path=Beschreibung}" Header="Beschreibung" />
</toolkit:DataGrid.Columns>
</toolkit:DataGrid>
</Grid>
</DataTemplate>
</toolkit:DataGrid.RowDetailsTemplate>
<toolkit:DataGrid.Columns>
<toolkit:DataGridTextColumn Binding="{Binding Path=LfdNr}" Header="LfdNr" />
<toolkit:DataGridTextColumn Binding="{Binding Path=Gruppe}" Header="Gruppe" />
</toolkit:DataGrid.Columns>
</toolkit:DataGrid>
</Grid>
</DataTemplate>
</toolkit:DataGrid.RowDetailsTemplate>
<toolkit:DataGrid.Columns>
<toolkit:DataGridTextColumn Binding="{Binding Path=LfdNr}" Header="LfdNr" />
<toolkit:DataGridTextColumn Binding="{Binding Path=Gruppe}" Header="Gruppe" />
</toolkit:DataGrid.Columns>
</toolkit:DataGrid>
因此,当我查看已编译的程序时,子DataGrids显示我绑定到它们的表的所有Colums,而不仅仅是我所说的那个。 所以,我希望你能帮助我。
答案 0 :(得分:0)
这是一个非常简单的错误,我忘了“AutoGenerateColums = false”标签-.-