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>
Set VirtualizingStackPanel.IsVirtualizing
to false on the ListBox
or set a normal StackPanel
as the ListBox.ItemsPanel
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With