SharedSizeGroup
is a great mechanism to align multiple columns or rows between Grid
s in WPF, but it can have unexpected performance implications. I recently came across this when I used it inside the ItemTemplate
of a ListBox
. A few items in there, and everything works as expected, but after putting in a few dozen, it became really sluggish, and the app was permanently burning CPU cycles.
I redid the design without the need for the size group, removed the Grid.IsSharedSizeScope
from the list box, and performance was restored. This was with .net framework 4.8.1.
While researching the problem, I also learned:
-
ScrollViewer.CanContentScroll
can be used to switch the scrolling between ensuring that the top element is aligned (true), and continuous scrolling (false) -
SharedSizeGroup
can also be used with multiple columns/rows in the same grid, if you want them equal.