Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the ListView only showing 12 items?

I took the standard Item GridView template and modified it a bit to fit my needs. I actually have changed very little of the template code.

I have a single group, and I have a lot of items in it (92 items). The listview does render some of them, but it only renders 12 of them. Why is that? How can I override that and make it display all of the items?

Here's a screenshot of me broken into the debugger as I'm setting the DefaultViewModel: enter image description here

I add items to my listview like so (as I parse XML from a service):

DataSource.AddItem(new DataItem(... title, name, etc, DataSource.getGroup("gallery")));

Then in my DataSource class (this is exactly the same one as the sample, I just renamed it), I added this method:

public static void AddItem(DataItem item)
{
    item.Group.Items.Add(item);
}

Here's what the XAML that renders this looks like (it's the same as the GridView template:

    <GridView.ItemsPanel>
                <ItemsPanelTemplate>                        
                    <VirtualizingStackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </GridView.ItemsPanel>
            <GridView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <Grid Margin="1,0,0,6">
                                <Button
                                    AutomationProperties.Name="Group Title"
                                    Content="{Binding Title}"
                                    Click="Header_Click"
                                    Style="{StaticResource TextButtonStyle}"/>
                            </Grid>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                    <GroupStyle.Panel>
                        <ItemsPanelTemplate>
                            <VariableSizedWrapGrid Orientation="Vertical" Margin="0,0,80,0"/>
                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>
                </GroupStyle>
            </GridView.GroupStyle>
        </GridView>

I'd really appreciate any help.

like image 815
Nico Avatar asked Dec 06 '25 20:12

Nico


1 Answers

Grid application template limits amount of items displayed in each group to 12 for reasons explained in the comment below:

public class SampleDataGroup : SampleDataCommon
{
    ...
    public IEnumerable<SampleDataItem> TopItems
    {
        // Provides a subset of the full items collection to bind to from a GroupedItemsPage
        // for two reasons: GridView will not virtualize large items collections, and it
        // improves the user experience when browsing through groups with large numbers of
        // items.
        //
        // A maximum of 12 items are displayed because it results in filled grid columns
        // whether there are 1, 2, 3, 4, or 6 rows displayed
        get { return this._items.Take(12); }
    }
}
like image 95
Denis Avatar answered Dec 08 '25 08:12

Denis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!