I have a list box containing any number of UIElement whose size is unknown.
I want to track the suggested size of the list box after adding each item. This will allow me to split a large list (for example: 100 items) into several (more than 10) smaller lists of approximately the same visual size, regardless of the visual size of each item in the list.
However, it seems that the Measure pass only affects the ListBox DesiredSize property the first time Measure is called:
public partial class TestWindow : Window { public TestWindow() { InitializeComponent(); ListBox listBox = new ListBox(); this.Content = listBox;
I tried to add a call:
listBox.InvalidateMeasure();
between adding items to no avail.
Is there an easy way to calculate the desired size of a ListBox (or any ItemsControl ) when adding time items?
source share