c# - ListView flashes black on resize when large number of items inside -


i have listview based control. it's file explorer. when path property set, first file system items loaded asynchronous method (using win32 api). super fast large number of files. anyway, c:\windows\system32 don't see lag. items added listview in batches of 64, after each 64 dispatcher.yield() awaited show added before operation finishes. again makes whole thing way faster , more responsive.

there 1 not fast operation: when need icon file first time, have make system call. call made in getter, it's smart, tries use cache if available.

the loading of view blink.

however when load huge directory (no problem, fast) - , resize or maximize window - see black flash before control resizes.

it's first window resizes, added space painted black, larger listview appears. it's supper annoying , devastates smooth experience. there way avoid black space?

i tried set window background white, didn't help. tried set usercontrol containing listview background white. no joy.

when there not many items in listview there no black flash, it's still not smooth enough.

so - how prevent seeing black background while control being resized?

if has performance issues listview - here's should done it:

  1. do not execute expensive operations on ui thread. in case not it, similar. offending code hidden in item constructor, tried make string conversions on start. bad idea, expensive operations moved getters solved half of problem. item constructor should empty. no initial values. no initialization @ all. properties should read via getters. result in executing 20 such operations per view instead of 20000, if ui virtualization used.

  2. use mvvm pattern, not add items directly, create item source , add items source. allow built-in ui virtualization essential have large number of items. search "ui virtualization listview" in google more details. solved problem definitely.

  3. think of data virtualization if populating item source slow. in case unnecessary. when getting data relatively cheap - we're good. if not - have chunk of data needed shown.

  4. a simpler control template increase application performance little bit on low end mobile devices.

  5. if use unmanaged code anywhere in application, double check it, forgot calling destroyicon once, , resulted in weird, unexpected behavior. dispose disposable, destroy unused handles , such. make triple sure it's done, wasted countless hours on debugging such things. clear: unreleased resources didn't cause performance issues, caused other unexpected behavior weird exceptions, disappearing icons , such. issues seemed come listview though.


Comments