Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListBox is virtual by default?

Tags:

listview

wpf

I have a WPF ListBox with some user cards inside.
When one of those user cards is created (in the ideal case, when the current user receives it's friend list from the network), it makes a network request for a user's information.
When I scroll in the ListBox , wait a few seconds, and scroll back, the user cards have their default state.
Upon debugging, I noticed they are unloaded and recreated.

How can I stop the ListBox from virtualizing the items like this?


Code:

            <ListBox x:Name="friend_list" Background="{x:Null}" BorderBrush="{x:Null}">
                <ListBox.ItemTemplate>
                    <DataTemplate DataType="data:User">
                        <stuff:UserCard UserID="{Binding Path=UserID}" HorizontalAlignment="Stretch" Margin="0,0,0,0" />
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
like image 901
Vercas Avatar asked Nov 10 '12 22:11

Vercas


1 Answers

Set VirtualizingStackPanel.IsVirtualizing to false on the ListBox or set a normal StackPanel as the ListBox.ItemsPanel.

like image 153
H.B. Avatar answered Nov 15 '22 10:11

H.B.