Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

6
[C#] [UWP] Listbox keeps repeating first items
Author Summary
vixez is in UWP
Post Body

Hello,

I have a simple listbox that loads items (in my test case 135). I logged all the ID's of the items that are loaded, and they all have a unique ID. The listbox datatemplate is a usercontrol, so in the usercontrol I also logged the ID's to see which ones are loaded.

Now is where it starts going wrong, it only loads about the first 10 items (I think whatever is initially visible), and then keeps repeating those first items over and over again. So instead of 135 unique objects, I have 135 objects that are one of the first 10 or so loaded.

You can see the logging here (there are a lot more ID's not visible).

After the User Control ID's line, that's the only ID's it loads and keeps looping those 10 ID's until there are 135 items in the listbox.

This is the full page code

<Style x:Key="ListBoxItemStyle1" TargetType="ListBoxItem">
    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>

    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ListBoxItem">
                <Border x:Name="LayoutRoot" BorderThickness="3">

                    <ContentControl x:Name="ContentContainer" 
                        VerticalContentAlignment="Top" 
                        HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"  
                        Margin="{TemplateBinding Padding}" 
                        Content="{TemplateBinding Content}" 
                        ContentTemplate="{TemplateBinding ContentTemplate}" 
                        Foreground="{TemplateBinding Foreground}" />
                </Border>

            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
</Page.Resources>

 <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"></RowDefinition>
        <RowDefinition></RowDefinition>
    </Grid.RowDefinitions>
    <SearchBox x:Name="sbSearch" QuerySubmitted="sbSearch_QuerySubmitted" Margin="12,12,12,0"></SearchBox>


    <ListBox x:Name="lbResults" Grid.Row="1" ItemContainerStyle="{StaticResource ListBoxItemStyle1}" Background="{x:Null}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <userControls:WantlistItem Tag="{Binding}"></userControls:WantlistItem>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</Grid>
</Grid>

Loading of listbox in main page

private void Page_Loaded(object sender, RoutedEventArgs e)
{
    if(Variables.WantsAll == null) Helpers.GetWantList();
    foreach (var v in Variables.WantsAll)
    {
        Debug.WriteLine(v.id);
    }
    Debug.WriteLine("--- USER CONTROL ID's ---");
    lbResults.ItemsSource = Variables.WantsAll;


}

In the UserControl Page_Loaded I'm logging them as well.

In this screenshot you can see I scrolled down, and it starts repeating the same items again (sometimes it messes up, as you can see the first item is not correctly repeated, it's a different one).

Note that in front of the names I added the ID's it prints out, you can see it's repeating the same ID's (for example the green album: 1301162), even tho in the list I set as ItemsSource it only exists once (all items are unique).

I started a StackOverflow issue here as well.

What am I doing wrong?

Author
Account Strength
100%
Account Age
12 years
Verified Email
Yes
Verified Flair
No
Total Karma
5,424
Link Karma
873
Comment Karma
4,551
Profile updated: 4 days ago
Posts updated: 8 months ago

Subreddit

Post Details

Location
We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
8 years ago