3

When using DevExpress, I see this error:

DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled Message="By default, an infinite grid height is not allowed since all grid rows will be rendered and hence the grid will work very slowly. To fix this issue, you should place the grid into a container that will give a finite height to the grid, or you should manually specify the grid's Height or MaxHeight. Note that you can also avoid this exception by setting the GridControl.AllowInfiniteGridSize static property to True, but in that case the grid will run slowly."

Contango
  • 76,540
  • 58
  • 260
  • 305

3 Answers3

6

The problem is that the DXGrid has an infinite height.

To fix, set the height to something non-infinite.

Snoop is absolutely invaluable for this:

enter image description here

If the "Height" for the XAML element is infinite (i.e. 0 or NaN), you can set it using one of the following:

  • Option 1: Height="{Binding Path=ActualHeight, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UIElement}}"
  • Option 2: VerticalAlignment="Stretch"
  • Option 3: Height="Auto"

Hint: Use VerticalAlignment="Stretch" if you are a child of a Grid with a <RowDefinition Height="*">, and the Binding RelativeSource... elsewhere if that doesn't work.

But what if the parent control has an infinite height?

If the parent control has an infinite height, then we have a bigger problem. We have to keep setting the height of each successive parent, until we hit a control with a non-infinite ActualHeight.

Appendix A: Related Posts

Community
  • 1
  • 1
Contango
  • 76,540
  • 58
  • 260
  • 305
  • none of these doesn't work for me, I have my grid in an exapander in an ItemControl – Salah Alshaal Feb 20 '18 at 16:27
  • What is the ActualHeight of the control? If it is infinite, look at ActualHeight of the parent, and repeat until you find a parent with a finite height. Then work your way down, setting the height of all controls until you hit your one. – Contango Feb 26 '18 at 18:24
4

It is a possible case when your grid has no parent with the finite height. For example, as a ScrollViewer content.

To fix that, you can set static property GridControl.AllowInfiniteGridSize to true, but GridControl will not use the virtualization mechanism in that case.

So, the better option here is to set MaxHeight for it. But since grids are usually very dynamic at the size, simple constant for MaxHeight wouldn't be the best.
You may want to calculate actual max height for your grid. DXBinding might be helpful here:

<dxg:GridControl
     MaxHeight="{DXBinding '@s.VisibleRowCount * $const:GridHelper.RowMaxHeight'}" />

where RowMaxHeight is your constant that is also used for cell templates

Sasha Kravchuk
  • 161
  • 2
  • 2
3

To add to this, I recently had the same issue and I ended up binding MaxHeight to the screen height. Might not apply in all scenario's, but it's a quick fix for most.

<dxg:GridControl MaxHeight="{x:Static SystemParameters.PrimaryScreenHeight}" />