MahApps / MahApps.Metro

A framework that allows developers to cobble together a better UI for their own WPF applications with minimal effort.
https://mahapps.com
MIT License
9.32k stars 2.44k forks source link

listview / datagrid speed #3138

Closed sergeypyrkin closed 6 years ago

sergeypyrkin commented 6 years ago

Hi I testing speed of updatting datagrid; for 1) pure wpf 2) metro 3) metro + clearstyles

wht is clearstyles <ListView Style="{StaticResource clearListView} ......

where clearListView is empty style

My control ` <ListView x:Name="dataGridView1" Grid.Row="1" Grid.Column="0" Margin="3" HorizontalAlignment="Stretch" BorderBrush="#FF25A0DA" BorderThickness="1" FontFamily="Microsoft Sans Serif" FontSize="11" Foreground="#FF000000" IsTextSearchEnabled="False" KeyboardNavigation.DirectionalNavigation="Cycle"

            >
        <ListView.ItemContainerStyle>
            <Style TargetType="{x:Type ListViewItem}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding FlagSaved}" Value="true">
                        <Setter Property="Foreground" Value="Black" />
                        <Setter Property="Background" Value="LightGray" />
                    </DataTrigger>

                    <DataTrigger Binding="{Binding FlagUpdate}" Value="true">
                        <Setter Property="Foreground" Value="Black" />
                        <Setter Property="Background" Value="Gray" />
                    </DataTrigger>

                    <DataTrigger Binding="{Binding FlagGenerated}" Value="true">
                        <Setter Property="Foreground" Value="DarkOliveGreen" />
                        <Setter Property="Background" Value="White" />
                    </DataTrigger>

                    <DataTrigger Binding="{Binding isBallParse}" Value="true">
                        <Setter Property="Foreground" Value="DarkGreen" />
                        <Setter Property="Background" Value="White" />
                    </DataTrigger>

                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="Foreground" Value="White" />
                        <Setter Property="Background" Value="Blue" />
                    </Trigger>
                    <DataTrigger Binding="{Binding IsCritical}" Value="true">
                        <Setter Property="Foreground" Value="White" />
                        <Setter Property="Background" Value="Red" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding IsWarning}" Value="true">
                        <Setter Property="Foreground" Value="Black" />
                        <Setter Property="Background" Value="Yellow" />
                    </DataTrigger>

                    <DataTrigger Binding="{Binding FlagDel}" Value="true">
                        <Setter Property="Foreground" Value="Gray" />
                        <Setter Property="Background" Value="White" />
                    </DataTrigger>
                </Style.Triggers>

            </Style>
        </ListView.ItemContainerStyle>
        <ListView.View>
            <GridView>
                <GridViewColumn
                        Width="70"
                        DisplayMemberBinding="{Binding A1}"
                        Header="A1" />
                <GridViewColumn
                        Width="70"
                        DisplayMemberBinding="{Binding A2}"
                        Header="A2" />
                <GridViewColumn
                        Width="70"
                        DisplayMemberBinding="{Binding A3}"
                        Header="A3" />
                <GridViewColumn
                        Width="70"
                        DisplayMemberBinding="{Binding A4}"
                        Header="A4" />
                <GridViewColumn
                        Width="70"
                        DisplayMemberBinding="{Binding A5}"
                        Header="A5" />
                <GridViewColumn
                        Width="70"
                        DisplayMemberBinding="{Binding A6}"
                        Header="A6" />
                <GridViewColumn
                        Width="70"
                        DisplayMemberBinding="{Binding A7}"
                        Header="A7" />
                <GridViewColumn
                        Width="70"
                        DisplayMemberBinding="{Binding A8}"
                        Header="A8" />

            </GridView>
        </ListView.View>
    </ListView>

`

what time i calculate dataGridView1.ItemsSource = items.OrderBy(o => o.A1).ThenBy(o => o.A2).ThenBy(o => o.A3).ThenBy(o => o.A4); dataGridView1.Items.Refresh();

RESULT

itog

punker76 commented 6 years ago

@sergeypyrkin It would be nice if you can add a link to your test application. You also forgot to say which MahApps version you tested.

sergeypyrkin commented 6 years ago

https://github.com/sergeypyrkin/gridtest

sergeypyrkin commented 6 years ago

1.5.0 it last

punker76 commented 6 years ago

@sergeypyrkin

1) Compile and run your application gives me many BindingExpression warnings at the output window in VS.

System.Windows.Data Error: 40 : BindingExpression path error: 'FlagDel' property not found on 'object' ''Item' (HashCode=16974962)'. BindingExpression:Path=FlagDel; DataItem='Item' (HashCode=16974962); target element is 'ListViewItem' (Name=''); target property is 'NoTarget' (type 'Object')
System.Windows.Data Error: 40 : BindingExpression path error: 'IsWarning' property not found on 'object' ''Item' (HashCode=16974962)'. BindingExpression:Path=IsWarning; DataItem='Item' (HashCode=16974962); target element is 'ListViewItem' (Name=''); target property is 'NoTarget' (type 'Object')
System.Windows.Data Error: 40 : BindingExpression path error: 'IsCritical' property not found on 'object' ''Item' (HashCode=16974962)'. BindingExpression:Path=IsCritical; DataItem='Item' (HashCode=16974962); target element is 'ListViewItem' (Name=''); target property is 'NoTarget' (type 'Object')
System.Windows.Data Error: 40 : BindingExpression path error: 'isBallParse' property not found on 'object' ''Item' (HashCode=16974962)'. BindingExpression:Path=isBallParse; DataItem='Item' (HashCode=16974962); target element is 'ListViewItem' (Name=''); target property is 'NoTarget' (type 'Object')
System.Windows.Data Error: 40 : BindingExpression path error: 'FlagGenerated' property not found on 'object' ''Item' (HashCode=16974962)'. BindingExpression:Path=FlagGenerated; DataItem='Item' (HashCode=16974962); target element is 'ListViewItem' (Name=''); target property is 'NoTarget' (type 'Object')
System.Windows.Data Error: 40 : BindingExpression path error: 'FlagUpdate' property not found on 'object' ''Item' (HashCode=16974962)'. BindingExpression:Path=FlagUpdate; DataItem='Item' (HashCode=16974962); target element is 'ListViewItem' (Name=''); target property is 'NoTarget' (type 'Object')
System.Windows.Data Error: 40 : BindingExpression path error: 'FlagSaved' property not found on 'object' ''Item' (HashCode=16974962)'. BindingExpression:Path=FlagSaved; DataItem='Item' (HashCode=16974962); target element is 'ListViewItem' (Name=''); target property is 'NoTarget' (type 'Object')

2) Your work routine which creates these random stuff blocks the UI

sergeypyrkin commented 6 years ago
  1. i copy this grid from enather project and forget clear styletrigger, you can delete in xaml all. it's not change result
  2. i think you launch grid whith 2000 items or more. change to 100, 200 , 500 i change data (1 create item, 1 delete, 2 update) whith method called shuffleData then stopwatch.start dataGridView1.ItemsSource = items.OrderBy(o => o.A1).ThenBy(o => o.A2).ThenBy(o => o.A3).ThenBy(o => o.A4); dataGridView1.Items.Refresh(); stopwatch.stop

and save time of iteration last time of iteration write in right bottom textbox left bottom textbox - its average

sergeypyrkin commented 6 years ago

Your work routine which creates these random stuff blocks the UI

yes , i think you right but add clearstyles <ListView Style="{StaticResource clearListView} . and you see how fast it's will be

i test pure wpf or metro + clearstyle with 2000 items or more, and i no see any block UI. Or time of block will be small. But pure metro with 1000 items take long block

punker76 commented 6 years ago

@sergeypyrkin Ok, found the reason. The default ListView style doesn't use virtualizing. So changing to Style="{StaticResource VirtualisedMetroListView}" fixes this.

sergeypyrkin commented 6 years ago

yes) i test just now - it work