locked
Listview fails to display text of list items when item count exceeds 400 items

    Question

  • I can get a large amount of items to display within a Listview.

    However, when I apply a DataTemplate, the listsview does not display any items.

    This works:

    <ListView x:Name="ContactList" ItemsSource="{Binding SelectedCategory.Contacts}" Height="425" Width="425" Margin="58,175,0,0" Canvas.ZIndex="99" Background="Transparent" Foreground="#FF333747" VerticalAlignment="Top" HorizontalAlignment="Left"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.Template> <ControlTemplate TargetType="ItemsControl"> <Border> <ScrollViewer> <ItemsPresenter/> </ScrollViewer> </Border> </ControlTemplate> </ItemsControl.Template> <ItemsControl.ItemTemplate> <DataTemplate> <TextBlock Text="Hello Wworld" /> </DataTemplate> </ItemsControl.ItemTemplate> </ListView>

    This doesn't:

    <ListView x:Name="ContactList" ItemsSource="{Binding SelectedCategory.Contacts}"
                Height="425"
                Width="425"
                Margin="58,175,0,0"  Canvas.ZIndex="99"
                Background="Transparent" Foreground="#FF333747" 
                VerticalAlignment="Top" HorizontalAlignment="Left">
    
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <VirtualizingStackPanel />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    
        <ItemsControl.Template>
            <ControlTemplate TargetType="ItemsControl">
                <Border>
                    <ScrollViewer>
                        <ItemsPresenter/>
                    </ScrollViewer>
                </Border>
            </ControlTemplate>
        </ItemsControl.Template>
    
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding DisplayName}" />
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ListView>

    It appears that displaying listview items using a data template fails once a binding is applied. How can I resolve this?


    Monday, August 25, 2014 1:00 PM

Answers

  • My list was displaying several items that had empty strings.

    As a result of this list being sorted in ascending order, the items that displayed empty text showed up at the beginning of the list while the other items did exist but were not within the scrollviewer's viewport.

    As a result I did this:

        foreach (var contact in phoneContacts)
        {
            if (contact.DisplayName == string.Empty)
            {
                continue;
            }
        .
        .
        .
         }

    • Marked as answer by Scott Nimrod Monday, August 25, 2014 4:32 PM
    Monday, August 25, 2014 4:32 PM