Answered by:

WPF DataGrid Column Width issue

Question

I have a simple window with 2 tabs, and 4 datagrids. I set up each one with similar, if not identical settings. They all get their own DataSet based binding, and have standard Text columns, and combo box columns. Recently (past week) of
development, while I was adding filtering/sorting/grouping features to my program, the column widths have begun to ingore my settings. By collapsed I mean approx 20 pixels wide (just enough for the sorting Icon).

Contacts datagrid, works great in run time, but in design time the columns are all collapsed.

ContactsToClients data grid has no abnormal issues

Clients datagrid AND Clients to Contacts datagrid look great in design time, but show collapsed columns in run time.

How do I hunt down the problem? I've tried removing all the temporary code, and rebuilding, closing Visual Studio and reopening. I've remmed out the sorting code. None of these have any affect. It appears that my settings are all
being ignored. Here is the XAML code:

All replies

The datagrid will display the proper width If I take the Dynamic "*" out of the equations. If I put just one * in it, they all collapse. This is a new (and wrong) behavior, and I would like to fix it. Any ideas? I read
mention of an issue with DataGrid's on second page of a tab control, Mine is the same, are these related bugs?

This solved a similar problem for me, using the WPF 4.0 Datagrid, where the columns would be incorrectly sized (collapsed to minimum specified sizes) the first time the grid was display & then correctly when the datasource was updated.

It was driving me crazy & I had no idea why this was happening, until I stumbled on this post, looking for something else.

Is this something that will be "fixed" at some stage, or is this expected beahvior that will remain as it is, the only solution being adding those lines?

I have used the solution and i works perfectly with one problem. I have CollectionView with explicitly defined groups. If the number of items in collection is less then the number of groups only the same number of groups as the number of items is displayed.
With StackPanel as ItemsPanelTemplate the groups are shown correctly but there is a problem with column collapsing. Does anybody know a solution of this problem?

I have solved a similar problem by specify explicit width to its parent container, which is a dockpanel in my case. For anyone who might have this problem, if none of these answers above can solve your problem,just try my solution.