简体   繁体   English

DevExpress.Wpf.Grid.InfiniteGridSizeException 未处理

[英]DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled

When using DevExpress, I see this error:使用 DevExpress 时,我看到此错误:

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." DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled Message="默认情况下,不允许无限网格高度,因为将呈现所有网格行,因此网格工作非常缓慢。要解决此问题,您应该将网格放入为网格提供有限高度的容器,或者您应该手动指定网格的高度或最大高度。请注意,您也可以通过将 GridControl.AllowInfiniteGridSize 静态属性设置为 True 来避免此异常,但在这种情况下,网格将运行缓慢.”

The problem is that the DXGrid has an infinite height. 问题是DXGrid具有无限高度。

To fix, set the height to something non-infinite. 要修复,请将高度设置为非无限的。

Snoop is absolutely invaluable for this: Snoop绝对是非常宝贵的:

在此输入图像描述

If the "Height" for the XAML element is infinite (ie 0 or NaN ), you can set it using one of the following: 如果XAML元素的“高度”是无限的(即0NaN ),则可以使用以下方法之一进行设置:

  • Option 1: Height="{Binding Path=ActualHeight, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UIElement}}" 选项1: Height="{Binding Path=ActualHeight, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UIElement}}"
  • Option 2: VerticalAlignment="Stretch" 选项2: VerticalAlignment="Stretch"
  • Option 3: Height="Auto" 选项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. 提示:如果您是具有<RowDefinition Height="*">Grid的子项,则使用VerticalAlignment="Stretch"如果<RowDefinition Height="*"> ,则使用Binding RelativeSource...其他地方。

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 . 我们必须继续设置每个连续父级的高度,直到我们使用非无限的ActualHeight命中控件。

Appendix A: Related Posts 附录A:相关文章

It is a possible case when your grid has no parent with the finite height. 当您的网格没有具有有限高度的父级时,可能会出现这种情况。 For example, as a ScrollViewer content. 例如,作为ScrollViewer内容。

To fix that, you can set static property GridControl.AllowInfiniteGridSize to true , but GridControl will not use the virtualization mechanism in that case. 要解决此问题,可以将静态属性GridControl.AllowInfiniteGridSize设置为true ,但GridControl在这种情况下不会使用虚拟化机制。

So, the better option here is to set MaxHeight for it. 所以,这里更好的选择是为它设置MaxHeight But since grids are usually very dynamic at the size, simple constant for MaxHeight wouldn't be the best. 但由于网格通常在大小上非常动态,因此MaxHeight的简单常量不是最好的。
You may want to calculate actual max height for your grid. 您可能想要计算网格的实际最大高度。 DXBinding might be helpful here: DXBinding在这里可能会有所帮助:

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

where RowMaxHeight is your constant that is also used for cell templates 其中RowMaxHeight是您的常量,也用于单元格模板

To add to this, I recently had the same issue and I ended up binding MaxHeight to the screen height.除此之外,我最近遇到了同样的问题,我最终将 MaxHeight 绑定到屏幕高度。 Might not apply in all scenario's, but it's a quick fix for most.可能不适用于所有场景,但它是大多数情况下的快速修复。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM