views:

323

answers:

3

Hi,

I have a DataGrid with some template columns that contain another DataGrid. My problem is that if some rows have a lot of content in them their height doesn't adjust so the whole content is visible, but rather it's cut off, giving the impression that the rows overlap. However, as soon as I add a new row to the grid or add a new row to the mini-grid inside one of the main grid's rows, the layout gets updated and the row heights are resized correctly.

So the problem is only when loading the grid the first time.

Is there a way to force the grid to size the rows heights to their content?

Thanks

A: 

Hi Adrian,

I'm not sure what is this, but you could try call InvalidateVisual(), some time later, when element is loaded. This forces complete new layout pass...

Anvaka
A: 

The DataGrid in my UserControl is doing the same thing. In this example, there are only 32 rows of data with five DataGridTemplateColumns consisting of an <Image> and four <TextBlock>s.

My control shows search results, if I rerun the same search it does not always do this. In addition, the cropping only occurs, roughly, on the first pageful of results. Rows further down are ok.

Using InvalidateVisual() does not help.

If anyone has any ideas on how to solve this or can indicate if this is a known issue with that control, I'd be interested in hearing about it.

dh0well
A: 

I had some serious trouble with this (bug?) today, so I'll share what I tried and what almost worked... (And hope that someone knows an actual fix)

In my case the bug only appeared when there were 10 or more rows. Out of the rows, ten first rows would in some cases have too small height for the contents. (I first thought that the nine items were drawn on top of each other, which was stupid of me.) There are quite many columns, so there's a scrollbar. Clicking on the scrollbar resizes the heights to proper values.

Some things that in my experience do not work:

  • Changing virtualization settings had no effect.
  • InvalidateVisual() and InvalidateArrange() don't work. Tried both datagrid and its parent.
  • Changing the height of datagrid did not work (although I'm not quite happy with my tests here)
  • Forcing the datatemplates of the cells to a specific size did not have an effect.
  • Placing the datagrid inside a scrollviewer (so that the datagrid would have all the space it could ever need...) did not work.

However:

The one thing (I found) that the datagrid seems to respect is MinRowHeight-setting, so now I've got there a moronic value and I'm hoping that this won't cause problems later on when the datatemplates are modified.

TuomoT