为什么Width =“*”不适用于位于RowDetailsTemplate中的DataGrid中的列

时间:2012-12-22 13:58:19

标签: wpf datagrid rowdetailstemplate

如果我使用“*”设置DataGrid(位于RowDetailesTemplate)列的宽度 - 列缩放不起作用

<DataGrid>
...
<DataGrid.RowDetailsTemplate>
   <DataTemplate>
      <DataGrid Margin="10" Height="100">
         <DataGrid.Columns>
            <DataGridTextColumn Header="header A" Width="3*" />
            <DataGridTextColumn Header="header B" Width="2*" />
            <DataGridTextColumn Header="header C" Width="*" />
         </DataGrid.Columns>
      </DataGrid>
    </DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>

enter image description here

但如果我用Grid替换DataGrid并使用“*”scailing works设置它的列宽

<Grid Margin="5" Height="100">
   <Grid.ColumnDefinitions>
      <ColumnDefinition Width="3*"></ColumnDefinition>
      <ColumnDefinition Width="2*"></ColumnDefinition>
      <ColumnDefinition Width="*"></ColumnDefinition>
   </Grid.ColumnDefinitions>

   <TextBlock Text="header A" Background="LightGray" TextAlignment="Center" HorizontalAlignment="Stretch"></TextBlock>
   <TextBlock Text="header B" Grid.Column="1" TextAlignment="Center" HorizontalAlignment="Stretch"></TextBlock>
   <TextBlock Text="header C" Grid.Column="2" Background="LightGray" TextAlignment="Center" HorizontalAlignment="Stretch"></TextBlock>
</Grid>

enter image description here

如何修复DataGrid缩放?

溶液

<DataGrid HorizontalScrollBarVisibility="Disabled">
...
<DataGrid.RowDetailsTemplate>
...
</DataGrid.RowDetailsTemplate>
</DataGrid>

1 个答案:

答案 0 :(得分:16)

这只是基于此question的猜测。

设置ScrollViewer.HorizontalScrollBarVisibility="Disabled"