0

I am searching for this long time and i couldn't get it.

I have a Long list selector in my windows phone 8 project. How can i manage the button event in each item in the data template? I need to get the selected item in that button event. Code snippet shown below. Please help.

code snippet

randominstanceOfLivingThing
  • 16,873
  • 13
  • 49
  • 72
Ramin
  • 71
  • 1
  • 4

2 Answers2

0

try this

// in your button click event type this code

var selectedValue = ((sender as Button).dataTemplate;

              or

var selectedValue = ((sender as Button).dataTemplate as SbCaDd).AcNo;

0

If you want to access the dataContext then try this one.

XAML

<phone:LongListSelector Grid.Row="1"
                        Name="llsMsg"
                        LayoutMode="List"
                        VirtualizingStackPanel.VirtualizationMode="Recycling">
    <phone:LongListSelector.ItemTemplate>
        <DataTemplate>
           <StackPanel>
              <Grid>
                 <TextBlock Text="{Binding}"
                             Foreground="Black" />
                 <Button Content="View Details"
                         Width="200"
                         Click="Button_Click"/>
                </Grid>
             </StackPanel>
        </DataTemplate>
    </phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>

C#

private void Button_Click(object sender, RoutedEventArgs e)
{
    var dataContext = (sender as Button).DataContext;
    var dataContext = (sender as Button).DataContext as YourDataModel; 
}
reza.cse08
  • 5,938
  • 48
  • 39