WPF DATAGRID COLUMN WIDTH

Jayden Bell

Total Post:110

Points:774
Posted by  Jayden Bell
WPF 
WPF
 1730  View(s)
Ratings:
Rate this:

I have a DataGrid in WPF with 3 columns. I would like these columns to take up all the space available in the grid. So for example:

Column 1 takes 40% of the grid's width Column 2 takes 30% of the grid's width Column 3 takes 30% of the grid's width

Such that even when resizing the window or grid the columns width resizes accordingly. Anyway I can achieve this.

Thanks

  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: WPF DataGrid Column Width

    Hi Jayden,


    I see you already found the answer you were looking for based on your comment. However, in case anybody else runs across this question trying to figure out how to get the column ratios (like your example of Column 1 = 40%, Column 2 = 30%, Column 3 = 30%), you can specify the ratios with * sizing for column widths as follows:

    <Grid>

        <Grid.ColumnDefinitions>

            <ColumnDefinition Width="4*" />

            <ColumnDefinition Width="3*" />

            <ColumnDefinition Width="3*" />

        </Grid.ColumnDefinitions>

    </Grid>

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!