This week I visited a client who had performance issues in a mature application.
The problems were consisted of cpu overload, but also improper usage of some UI elements. The most obvious problem that immediately drew my attention was the massive usage of ViewBox
objects. The client had over 40 ViewBoxes all over the solution, some of them being used more than once in a running application.
So what is a ViewBox?
The ViewBox is a very nice feature of WPf which can surround other UI elements and affects the level of zoom in those elements. Changing the zoom level of a ViewBox causes its contents to grow (or shrink) in the same level. This also means the font size. Basically, I believe this ability should only be used on a group of elements, usually textual ones (for example a form), when we want a simple way to zoom in/out. Of course there are other scenarios where usage of a ViewBox is appropriate and useful, but one should be very carefull using this ability.
Adding a WPF ViewBox to our view overloads the UI thread, and may cause lags in our application's responsiveness.
After analyzing my client's application, we realized that most if not all of the ViewBoxes were not necessary, but rather used to change the size of a UI element once - a mission that can be achieved easily by using scaling
Removing all those ViewBoxes made the application much more responsive.
Please avoid using ViewBoxes as much as you can...