My application is loading a bunch of the same user control into a
ScrollPanel. The problem is, this is very slow.
The profiler show that the method
Application.LoadComponent(), which is called internally by in the designer code in the constructor of my user control, is the bottleneck. The documentation of this method says, that this method load XAML archivos.
The question is, how can I use BAML instead of XAML? How can I accomplish that the XAML for my user control must not be parse again and again when creating new instances from it? Is there another way to make loading my user controls faster?
preguntado el 08 de enero de 11 a las 20:01
LoadComponent() already loads
.baml, don't worry about this bit of the question. Microsoft did this intentionally, to not let developers make dependencies on
baml format. Going forward they can improve the format without breaking any existing applications.
Yes, there are another ways of making it work faster. The first optimization to take is UI virtualization. WPF already comes with handy VirtualizandoStackPanel. It works in tandem with ItemsControls, and has certain limitations (e.g. if you create items containers and add them by your own, you loose virtualization, or if you set
ScrollViewer.CanContentScroll="False" you loose it again). To use virtualization you will probably have to rewrite your application to use
ItemsControl + DataBinding estilo (
ListBox already has virtualization enabled)
If you feel like you need even more information on UI virtualization refer to Dan Crevier's blog.
And final advice. You can try rewriting your UserControls to Custom Controls. My simple performance test showed the following figures. To create 10K controls with the same visual tree it took:
- for UserControl: 4932ms;
- for CustomControl: 86 ms; (~57 times faster)
Espero que esto ayude