ObservableCollection and ListBoxItem DataTemplate generation problem

后端 未结 3 1325
余生分开走
余生分开走 2021-01-15 05:55

Something strange is going on with ObservableCollection.

I have the following code:

private readonly ObservableCollection _displa         


        
3条回答
  •  执笔经年
    2021-01-15 06:28

    Actually, I was trying to get this to work and I found the ".UpdateLayout()" function, which works perfectly for me. I realize that you're doing vertical and I'm doing horizontal, but here's my code, it's pretty simple:

    for (int i = 0; i < listOfItems.ItemsIn.Count; ++i)
        {
            //CalculateItemsHeight(i);
    
            ListBoxItem abc = (lb.ItemContainerGenerator.ContainerFromItem(lb.Items[i]) as ListBoxItem);
            abc.UpdateLayout();
            totalWidth += abc.ActualWidth;
        }
    

    Hopefully this helps!

提交回复
热议问题