WPF SharedSizeGroup colum width changes for visible elements when scrolling

91 views Asked by At

How can I make one shared columns size for all elements in the listbox, also for elements that are outside of view. SharedSizeGroup working only for visible elements, but when I scroll down and elements in one of the columns becomes wider then the column becomes wider and opposite. How can I make shared size calculate max width of all elements also not visible and adjust the width one time? Excuse for my English. I hope someone can help me.

1

There are 1 answers

0
Keith Stein On

This is likely due to UI virtualization:

To improve performance, a ListBox uses UI virtualization by default. UIElement-based objects are created only for the items currently being displayed in the list. New UIElements are then created as additional items are scrolled into view.

Since the item isn't created yet, neither is the Grid inside, and so the SharedSizeGroup doesn't see it.

You can fix this by turning off UI virtualization for that ListBox:

<ListBox VirtualizingPanel.IsVirtualizing="False"/>

Note: you'll also lose all the performance benefits of UI virtualization, but that only becomes apparent if you have a large enough number of items you're displaying.