Val*_*ale 9 c# wpf performance xaml .net-4.0
我有以下场景:
<ScrollViewer>
<Grid>
<!--many other controls-->
<DataGrid />
</Grid>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud)
现在,当我将DataGrid绑定到大量数据(大约10,000行)时,我的性能非常慢.事实上,我得到OutOfmemory异常(我有8 GB的内存)!我在某处读到这是因为ScrollViewer重写了DataGrid虚拟化(或类似的东西),但我不知道如何防止这种情况.如果我删除ScrollViewer,问题就解决了!数据加载时间不到一秒钟.
我想保留ScrollViewer(因为其他控件)并且具有良好的性能.那可能吗?如果没有,还有其他解决方案吗?
这些问题的一个常见解决方法是在同一行中添加一个不可见的"大小调整元素" DataGrid,然后就可以绑定DataGrid.Height到ActualHeight大小调整元素了.这样,你DataGrid将永远消耗高度RowDefinition.例
<ScrollViewer>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Button Content="Some Control.." />
<Rectangle Name="sizingElement"
Grid.Row="1"
Fill="Transparent"
Margin="1"/>
<DataGrid Grid.Row="1"
Height="{Binding ElementName=sizingElement,
Path=ActualHeight, FallbackValue=1}">
<!--...-->
</DataGrid>
<Button Content="Some more controls etc.." Grid.Row="2"/>
</Grid>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2604 次 |
| 最近记录: |