简体   繁体   中英

Wpf Realtime DataBinding To Listview

I want to bind data (1000 record per second, i mean 25 records per 25 milisecond) to a listview and it must be ordered descending by datetime.

I have used observable collection. When i get data from the source (eg socket), i am adding to my collection by inserting the model at the zero index of observable collection.

 observableCollection.Insert(0, model);

It is working no problem but it is using %30 cpu (intel i5). And if i open these windows 10 times, my application is getting slower. I am using virtualizing properties. If i don't set the itemsource of the listview, cpu usage is about %0.

This is my listview:

 <ListView HorizontalAlignment="Stretch" VirtualizingStackPanel.IsVirtualizing="True"  VirtualizingStackPanel.VirtualizationMode="Recycling"   Name="listView" ScrollViewer.CanContentScroll="True" Grid.Column="0"   VerticalAlignment="Stretch"  ItemsSource="{Binding observableCollection}">
  <ListView.ItemsPanel>
    <ItemsPanelTemplate>
      <VirtualizingStackPanel></VirtualizingStackPanel>
    </ItemsPanelTemplate>
  </ListView.ItemsPanel>
  <ListView.View>

    <GridView>
      <GridViewColumn DisplayMemberBinding="{Binding ID}" Width="75"  Header="Id" />
      <GridViewColumn DisplayMemberBinding="{Binding Time}" Width="175"  Header="Time"  />
      <!-- Ten more columns -->
    </GridView>
  </ListView.View>
</ListView>

Is it correct to use listview?

How can i increase the performance?

Is there any other techniques to do this?

The INotifyCollectionChanged event of ObservableCollection is the bottleneck. Try to build your result list first, then to create an ObservableCollection from your list, and then assign the ObservableCollection to the ItemsSource of your control.

Consider a fake scroll bar by only adding the top 100 items to the list box but setting the maximum and value of a separate scroll bar to the actual data size and position. This requires more code to keep the scroll bar and list box in sync.

The amount of data and the number of updates is just too much and faking a long list might be the only solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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