Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

wpf - Why Width="*" doesn't work for columns in DataGrid located in RowDetailsTemplate

If I set widths of DataGrid (located in RowDetailesTemplate) columns using "*" - columns scaling doesn't work

<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

but if I replace DataGrid by Grid and set it's columns width using "*" 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

how to fix DataGrid scaling ?

solution:

<DataGrid HorizontalScrollBarVisibility="Disabled">
...
<DataGrid.RowDetailsTemplate>
...
</DataGrid.RowDetailsTemplate>
</DataGrid>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It is just a guess based on this question.

Set ScrollViewer.HorizontalScrollBarVisibility="Disabled".


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...