简体   繁体   中英

DataGridTextColumn Percentage Width

I have a DataGrid with 3 DataGridTextColumns within. I want the first to be 40% and the other two as 30%, basically I need them to fill the whole DataGrid.

                    <Grid>
                        <DataGrid ItemsSource="{}" IsReadOnly="True">
                            <DataGrid.Columns>
                                <DataGridTextColumn Header="Item1" Binding="{Binding Path=Item1}" />
                                <DataGridTextColumn Header="Item2" Binding="{Binding Path=Item2}" />
                                <DataGridTextColumn Header="Item3" Binding="{Binding Path=Item3}" />
                            </DataGrid.Columns>
                        </DataGrid>
                    </Grid>

Use the relative width * just like in a regular Grid column width setting:

<DataGrid.Columns>
  <DataGridTextColumn Header="Item1" 
                      Binding="{Binding Path=Item1}" 
                      Width="4*"/>
  <DataGridTextColumn Header="Item2" 
                      Binding="{Binding Path=Item2}" 
                      Width="3*"/>
  <DataGridTextColumn Header="Item3" 
                      Binding="{Binding Path=Item3}" 
                      Width="3*"/>
</DataGrid.Columns>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM