mr_nobody
mr_nobody

Reputation: 194

longListSelector get index

I have longListSelector:

        <DataTemplate x:Key="AddrBookItemTemplate" >
            <StackPanel VerticalAlignment="Top">
                <Grid Background="#3FCDCDCD" Margin="3,3,3,3">
                    <Image Source ="{Binding UrlImage}" Height="100" Width="100" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,0,0,0" Stretch="Fill"/>
                    <TextBlock Text="{Binding Title}" TextWrapping="Wrap" Margin="110,0,0,0" Foreground="Black" FontFamily="Portable User Interface"/>
                </Grid>
            </StackPanel>
        </DataTemplate>

    </phone:PhoneApplicationPage.Resources>

<phone:LongListSelector
  x:Name="AddrBook"
  Background="Transparent"
  ItemTemplate="{StaticResource AddrBookItemTemplate}"
  IsGroupingEnabled="true"
  HideEmptyGroups ="true"
  SelectionChanged="AddrBook_SelectionChanged"
                    />

Preview - name of my class

How can i get index of PressedItem? What should i write here -

 private void AddrBook_SelectionChanged(object sender, SelectionChangedEventArgs e)
        { }

Upvotes: 0

Views: 378

Answers (1)

techloverr
techloverr

Reputation: 2617

you should write

var longlistselector = (sender as LongListSelector);
int index = longlistselector.DataSource.IndexOf(longlistselector.SelectedItem);

Upvotes: 4

Related Questions