0

有我的布局:

<DataGrid x:Name="BooksGrid"
          DataContext="{Binding WorkingBooksSet, Mode=TwoWay}"
          ItemsSource="{Binding}"
          RowDetailsVisibilityMode="VisibleWhenSelected"
          AutoGenerateColumns="False"
          VerticalAlignment="Top" HorizontalAlignment="Stretch"
          ColumnWidth="*">
  <DataGrid.Columns>
    <DataGridTextColumn Binding="{Binding Id}" Width="Auto" IsReadOnly="True" />
    <DataGridTextColumn Binding="{Binding Title}" />
    ...
  </DataGrid.Columns>
  <DataGrid.RowDetailsTemplate>
    <DataTemplate>
      <DataGrid ItemsSource="{Binding Publications,  Mode=TwoWay}"
                AutoGenerateColumns="False"
                VerticalAlignment="Top" HorizontalAlignment="Stretch"
                ColumnWidth="*">
        <DataGrid.Columns>
          <DataGridTextColumn Binding="{Binding Id}" Width="Auto" IsReadOnly="True" />
          <DataGridTextColumn Binding="{Binding Publisher}" />
          <DataGridTextColumn Binding="{Binding ReleaseYear}" />
          ...
        </DataGrid.Columns>
      </DataGrid>
    </DataTemplate>
  </DataGrid.RowDetailsTemplate>
</DataGrid>

这是一扇窗户

如您所见,女儿DataGrid出于某种原因并没有填满所有可用空间,而是使它们变窄。此外,禁止手动调整列的大小。

我不理解这种行为,尤其是当“父”DataGrid使用相同的代码正确显示时

4

1 回答 1

1

将 * width 添加到子 DataGrid 中的一列。

       <DataGrid.Columns>
          <DataGridTextColumn Binding="{Binding Id}" Width="Auto" IsReadOnly="True" />
          <DataGridTextColumn Binding="{Binding Publisher}" />
          <DataGridTextColumn Binding="{Binding ReleaseYear}" Width="*" />
          ...
        </DataGrid.Columns>
于 2013-10-02T10:21:11.317 回答