2
votes

I have a datagrid that has its column width set to "Auto". When the datagrid is loaded the columns are the correct size. However, when I change the window width to a size smaller than the datagrid it resizes the columns in order to try and fit everything in the datagrid. When I expand the window size back to full size all the datagrid columns are no longer sized to the content but instead are all set to the same width as if the width is now set to "*".

Is there a way to prevent this from happening? I have tried CanUserResizeColumns="False" and setting the width of the column to a hard coded value.

I am also using materialdesigninxaml, not sure if this is causing this?

2

2 Answers

2
votes

That truly is the way it works in WPF. If you know ahead of time what size you want, you should specify it accordingly. So, instead of width="Auto" you specify width="123".

You could try to keep relative sizing such as this:

width="2*" .... width="*" ... width="10*"

this will ensure that column 1 is twice the size of column 2 and column 3 is 10 times the width of column 2. This, in addition of minWidth and maxWidth should get you where you want to be. Good luck

1
votes

Check to make sure any column definitions with a width of "*"