WPF Datagrid Column Width Percentage of Datagrid ActualWidth

I spent several hours on this without any results.

I just want to have a DataGrid with the number of columns X that supports the relative width of the Grid itself.

So for example:

  • Col 1: 10%
  • Col 2: 10%
  • Col 3: 10%

I set the style attached to the template of the DataGrid element. I tried to bind the width to the DataGrid itself (often to a circular reference), to another object (the value is included, but the DataGridColumn not updated), with the converter (the converter gets the correct value, then sets the column value, but despite returning different numbers, the column width never changes).

I set the SizeChanged event in the DataGrid itself and set the column width, in particular, the DID changed the column values, but each size event raised an event of a different size, etc. etc...

I am obviously too stupid to understand this myself, so if someone could provide me with a simple example of what, in my opinion, should be a simple task, I would be so grateful.

So, just to be clear, ALL I am looking for is a DataGrid with the number of columns X that supports a fixed% of the width of the DataGrid - almost the same as any table in HTML would be natively.

Thanks in advance.

+6
source share
1 answer

ColumnWidth The property is your friend.

 <DataGrid ColumnWidth="*"/> 
+7
source

Source: https://habr.com/ru/post/950315/


All Articles