ListView with columns and bindings performance

╄→尐↘猪︶ㄣ 提交于 2019-12-01 05:35:19

问题


I have performance issue with ListView:

Single item takes 13-30 ms to create (50 items is over 1 second). Virtualization (recyling mode) is on, but scrolling even 100 items is already very uncomfortable.

At first I thought it's layout problem. But the reason seems to be - bindings.

There are multiple columns and each column cell has different template with different bindings, as an example:

<GridViewColumn>
    <GridViewColumn.CellTemplate>
        <DataTemplate>
            <Grid>
                <TextBlock Text="{Binding Value}"
                           Visibility="{Binding IsEditable, Converter={local:TrueToCollapsedConverter}}" />
                <Grid local:GridBehavior.Columns=",auto"
                      Visibility="{Binding IsEditable, Converter={local:FalseToCollapsedConverter}}">
                    <TextBox Text="{local:ExceptionBinding Path=Value, Converter={local:DoubleToStringConverter}}"
                             local:TextBoxBehavior.SelectAllOnFocus="True"
                             local:ListBoxBehavior.SelectListBoxItemOnFocus="True" />
                    <TextBlock Grid.Column="1" Text="{local:Lng Key=Unit.mm}" />
               </Grid>
           </Grid>
       </DataTemplate>
   </GridViewColumn.CellTemplate>

Any single binding add something like 0.1 ms. There are 20 columns, each cell has from 1 to 20 bindings, so it leads to this:

Binding take majority of time, e.g. 2.83 of 3.07 ms for the first column on screenshot.

Is there a way to gain some performance? Am I doing some obvious mistake?

来源:https://stackoverflow.com/questions/38248842/listview-with-columns-and-bindings-performance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!