0 Comments

If you want to let the last column in a datagrid fill the datagrid, you should use the first columns width to auto en set the last column width to * and specify minimum widths for the columns:

<DataGrid Name="subsysteemSettingsDataGrid" AutoGenerateColumns="False" HeadersVisibility="Column" HorizontalAlignment="Stretch" Margin="10" HorizontalGridLinesBrush="LightGray" VerticalGridLinesBrush="LightGray" HorizontalScrollBarVisibility="Disabled" CanUserAddRows="False" BorderBrush="#FF8C8E94" SelectionUnit="FullRow" CellStyle="{StaticResource SelectedSubDataGridCellStyle}"> <DataGrid.Columns> <DataGridTextColumn Header="Name" Binding="{Binding Path=Name, Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" MinWidth="150" Width="Auto" /> <DataGridTextColumn Header="Value" Binding="{Binding Path=Value, Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" MinWidth="200" Width="*" /> </DataGrid.Columns> </DataGrid>

De screendump below shows the last column stretched to the width of the datagrid

 

image

One Reply to “How to stretch the last column to the width of the datagrid in WPF

  1. I want to set the window SizeToContent=”Width”. The datagrid strech the window to the full size of screen if i set the last column to Width=”*”. The window has correct size if columns in datagrid set to Auto, but the last is not stretch.
    I have no solution found for this problem…

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts