7

I've spent several hours looking at this with no results.

I simply want to have a DataGrid with X number of columns that maintains its relative width to the Grid itself.

So, for example:

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

I have set up a style that is attached to a DataGrid item template. I have attempted binding the width to the DataGrid itself (often a cyclical reference), to another object (the value comes in, but the DataGridColumn doesn't update), with a Converter (the converter gets the correct value, then sets the value of the column, but despite different numbers coming back, the width of the column never changes).

I've set up a SizeChanged event on the DataGrid itself and set the width of the columns specifically, which DID change the values of the columns, but each size event caused another size event, etc... etc...

I'm obviously too stupid to figure this out myself, so if anyone could provide me a simple example of what I imagine should be a simple thing to do, I'd be ever so grateful.

So, just to be clear, ALL I'm looking for is a DataGrid with X number of columns that maintain a fixed % of the DataGrid width itself - pretty much like any table in HTML would do natively.

Thanks in advance.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Aibynn
  • 115
  • 1
  • 8
  • are you columns static or dynamic. – yo chauhan Jul 26 '13 at 05:00
  • OK...some more information (now that it's later and I've had some time to look at it without my head exploding). The problem seems to be with the DataGrid inside of a listbox item template. Once in there, it's as if it doesn't get the resize event. The control itself is sized properly, but the columns simply don't update. Hopefully will be able to do a more thorough search now. – Aibynn Jul 26 '13 at 06:42

1 Answers1

7

ColumnWidth property is your friend.

<DataGrid ColumnWidth="*"/>
Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Nitesh
  • 7,261
  • 3
  • 30
  • 25
  • I'm marking this as the answer (because it will work), and it turns out my question was badly asked. I will ask another one which will hopefully help. =) – Aibynn Jul 26 '13 at 07:51