locked
Get listview item at a particular index RRS feed

  • Question

  •  <ListView x:Name="thumbnaillistview" 
                          IsItemClickEnabled="True" SelectionChanged="thumbnail_selection" 
                          ItemClick="thumbnail_ItemClick"  Loaded="thumbnails_load" ScrollViewer.HorizontalScrollBarVisibility="Hidden" Height="700" Width="1000" >
                    <ListView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapGrid Orientation="Horizontal" Height="auto" Width="1000"  />
                        </ItemsPanelTemplate>
                    </ListView.ItemsPanel>
                    <ListView.ItemTemplate >
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <StackPanel Orientation="Vertical">
                                    <Image x:Name="img1" Source="{Binding Image1}" Height="170" Width="130"  />
                                    <TextBox x:Name="pgno1" BorderBrush="Transparent" TextAlignment="Center" Background="Black" Foreground="White" 
                                         Text="{Binding Pagenum}" Height="30" Width="30" />
                                </StackPanel>
                                <StackPanel>
                                    <Image x:Name="img2" Source="{Binding Image2}" Height="170" Width="130" />
                                    <TextBox x:Name="pgno2" BorderBrush="Transparent" TextAlignment="Center" Background="Black" Foreground="White" 
                                         Text="{Binding Pagenum}" Height="30" Width="30"/>
                                </StackPanel>
                            </StackPanel>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>

    in above listview i have already assign  itemsource at page's load event. But at i can not access the item from index which is already there in a listview using below code after some index.

     for (i = 0; i < paths.Count(); i++)
                {
                    var ThumbnailItem = thumbnaillistview.ItemContainerGenerator.ContainerFromIndex(i);

    I don't understand where I'm going wrong. Is there any possible way to get item of listview at particular index.

    Regards,

    Tanvi.

    Monday, April 22, 2013 1:33 PM

Answers

  • Since "WrapGrid : OrientedVirtualizingPanel" is a Virtualizing Panel, you will only access those ListViewItems that have been effectively realized in the VisualTree. So, if you need to access all possible items at once, it looks like you'll have to revise your design by using a non virtualizing StackPanel or avoid to access all listview items in the intended manner.

    • Proposed as answer by Aaron Xue Wednesday, April 24, 2013 8:38 AM
    • Marked as answer by Aaron Xue Wednesday, May 8, 2013 9:45 AM
    Monday, April 22, 2013 2:16 PM