How do I make an event when I click on an Item?

4

I wanted to know if you have how to click on an item to perform an event / function, knowing that each item has its function.

I'm using LongListSelector

Código XAML

<phone:LongListSelector Name="lstConsPais"
    HorizontalAlignment="Left" 
    VerticalAlignment="Top" 
    LayoutMode="List" 
    IsGroupingEnabled="False"
    Width="456">
                <phone:LongListSelector.ItemTemplate>
                    <DataTemplate>
                        <Border BorderBrush="#111" Margin="0, 10, 0, 0" BorderThickness="0,0,0,2">
                            <StackPanel VerticalAlignment="Center" Orientation="Horizontal">
                                <Image Height="100" Width="100"  Source="{Binding NomeImgBandeira}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
                                <StackPanel Orientation="Vertical">
                                    <TextBlock Text="{Binding NomePais}" Style="{StaticResource PhoneTextGroupHeaderStyle}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="15,25,0,0" />
                                </StackPanel>
                            </StackPanel>
                        </Border>

                    </DataTemplate>
                </phone:LongListSelector.ItemTemplate>
            </phone:LongListSelector>

Note: The list is being populated from an XML file, and I wanted to get the name of the country

If yes, could you give examples? I'm using WP C#

    
asked by anonymous 28.04.2014 / 17:47

1 answer

2

In the LongListSelector has an event SelectionChanged that is responsible when any item is selected.

Code sample:

private void LongListSelector1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
     if (((LongListSelector)sender).SelectedItem != null)
     {
         object cons = ((LongListSelector)sender).SelectedItem;
         MessageBox.Show(cons.ToString());
     }
}

Note: (((LongListSelector) sender) .SelectedItem) , it can here return an object, a type, etc, then a break point and check what it is returning

Reference :

28.04.2014 / 18:07