如何提高Wpf DataGrid的高频单元更新性能(.net 4.5)?

时间:2017-07-28 16:10:06

标签: .net wpf performance wpfdatagrid

我在使用C#4.5开发的WPF桌面应用程序上使用DataGrid控件。此数据网格有150行和5列。使用带有DispatcherPriority.Background的BeginInvoke,每个单元格每分钟更新大约2-3次。这是DataGrid的代码片段:

<DataGrid ItemsSource="{Binding Simulations, IsAsync=True}" AutoGenerateColumns="False" CanUserDeleteRows="False" CanUserAddRows="False" CanUserResizeColumns="True"
                ColumnWidth="*" CanUserResizeRows="True" CanUserReorderColumns="False" SelectedItem="{Binding SelectedSimulation}" 
                      EnableRowVirtualization="True"
                      EnableColumnVirtualization="True">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Nome do Cenario Geológico" IsReadOnly="True" Binding="{Binding Path=GeologicalScenarioName, UpdateSourceTrigger=PropertyChanged, IsAsync=True}" />
                    <DataGridTextColumn Header="Estado da Simulação" IsReadOnly="True" Binding="{Binding Path=JobStatus, UpdateSourceTrigger=PropertyChanged}" />
                    <DataGridHyperlinkColumn Header="Link para pasta de trabalho" IsReadOnly="True" Binding="{Binding Path=LocalFolderPath, IsAsync=True}">
                        <DataGridHyperlinkColumn.ElementStyle>
                            <Style>
                                <EventSetter Event="Hyperlink.Click" Handler="SimulationHyperlinkClick"/>
                            </Style>
                        </DataGridHyperlinkColumn.ElementStyle>
                    </DataGridHyperlinkColumn>
                    <DataGridTemplateColumn>
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Button IsEnabled="{Binding Path=CanCancelSimulation, UpdateSourceTrigger=PropertyChanged, IsAsync=True}" Click="ButtonBaseOnClickSim">Cancelar Simulação</Button>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTextColumn Header="Tempo" IsReadOnly="True" Binding="{Binding Path=TimeRunning, UpdateSourceTrigger=PropertyChanged, IsAsync=True}" />
                </DataGrid.Columns>
            </DataGrid>

问题是由于更新次数,UI无响应。有人能给我一个如何改善表现的线索吗?

Thankx

0 个答案:

没有答案