I have a WPF application (.NET 4) that has a main window, and much less UserControls displayed inside this main window. Various actions performed by the user cause the displayed UserControls be replaced by other other controls with different data.
When I switch these controls, I run into performance issues. The WPF dispatch thread switches to 100% processor when loading controls. On older machines or with a large number of controls, this can lead to the application being blocked for up to 30 seconds!
Profiling shows that almost all this CPU time is spent on calling various InitializeComponent methods of all different UserControls - not a single control is significantly worse than any other, they all seem to take from 0.2 to 0.5 seconds (on my a car with a fast processor and a good graphics card).
As far as I know, InitializeComponent is where WPF actually loads the compiled xaml into memory.
I don’t understand what to do here. I would like to pre-initialize things in the background thread, but all WPF controls should be created and used in the dispatcher thread, so I don't think this is possible.
Otherwise, it looks like the only parameters I have to delete all my xaml ??
Any help would be greatly appreciated.
performance c # wpf
Orion edwards
source share