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

Asked

Viewed 178 times

4

I wanted to know if there is a way, when clicking 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 take the name of the country

If so, could you give examples? I am using WP C#

1 answer

2


In the Longlistselector has an event Selectionchanged who is responsible when an item is selected.

Code example:

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

Obs: (((Longlistselector)Sender). Selectedit), it can here return an object, a type, etc., then from a break point and check what it is returning

Reference:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.