I would just like a few tips when i want to create a responsive UI.
I know how to use:
Dispatcher
Task
BackgroundWorker
Threads
I am looking for more advance tips, like binding tips... When i have 50+ controls on my UI that needs to update.
PriorityBinding
Populating ComboBoxes
Populating ListBoxes, ListViews
When processing data in the background... Best practices maybe when it comes to long running proccess.
What else can i do to make my UI 100% responsive.
FastObservableCollection
Manipulating PresentationSource
Using PLinq or Linq on multiple threads by using
AsQueryable() for dynamic filtering of data sources than single threaded and thread agnostic CollectionView
.
Readymade Gifs over animation
Vitualization of non-virtualized panels like canvas
Deferred scrolling
Trigger.Exnter \ Exit Actions for animations.
BeginStoryboard.HandoffBehavior="Compose"
Using Hardware over software acceleration.
Avoiding WindowStyle=None
, AllowTransparency=true
, Background=Transparent
, TileMode
Configure RenderOptions.BitmpaScalingMode
as LowQuality and enable caching. Enable PresentationFontCache
windows service.
Use Staticresources
over Dynamicresources
Avoid inheritable dependency properties. Also avoid heavy operations in property changed call backs.
Use Freezable brushes. Avoid x:Name
/ Namescoping
/ Binding
to their Color
propertys them to be freezable all the time.
Set background of the border, if it encapsulates a visual than setting visual's background. Similar is if you have set a Brush
as background of a visual then specify Brush.Opacity
than Visual.Opacity
.
Value converters must have minimulistic code. use Binding.IsAsync
and PriorityBinding
wherever applicable.
Use Expanders
with IsExpanded=False
by default.
CompositionTarget.Rendering
fires on each rendering cycle so should be used only if required. Detatch it on any opportunity.
WPF DataGrid
should avoid heavy use of combobox columns and editable Template columns, as the combobx templates try to load selected value and use the display member path by actually searching it from the items source of each combobox and template columns leak when used with highly observable collections.
Use WPF Extedned Tooklit based Shader effects and New Pixel Shader APIs such as Blur, Shadow.
And Many more...
I always found lazy loading very helpful to prevent large data amounts being loaded at once, which is where most of the startup time goes when handling large amounts of data. Bind your records to virtualized item controls, to minimize the memory footprint (obviously WPF is your judge on what's necessary in memory).
But to be honest : Martin is quite right...50+ databound controls,...man, that's freakin' hell ;-)
And your quest for 100% responsiveness, I guess, needs further explanation. To my understanding, applications can be responsive or not (taking user input / producing output vs being stuck doing nothing). Do you aim best performance? Or is it a rowlocking-scenario you're facing (let the user edit other records while performing long tasks on certain records)?
I think some of what AngelWPF has mentioned can be found in this neat article on priority binding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With