Vercas
Vercas

Reputation: 9141

ListBox is virtual by default?

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>

Upvotes: 5

Views: 4622

Answers (1)

brunnerh
brunnerh

Reputation: 184516

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

Upvotes: 8

Related Questions