i have ListBox on my xaml page called MainListBox. i can get index that get selected, but how can i get the data from selected item ?
My MainListBox_SelectionChanged :
private void MainListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int noteID1 = MainListBox.SelectedIndex+1;
if (MainListBox.SelectedIndex != null)
{
//I can get the index that get selected,
Debug.WriteLine(MainListBox.SelectedIndex);
}
MainListBox.SelectedIndex = -1;
}
my XAML :
<ListBox x:Name="MainListBox" Margin="6,0,0,0" ItemsSource="{Binding Items}" SelectionChanged="MainListBox_SelectionChanged" Height="578" VerticalAlignment="Bottom" Grid.ColumnSpan="3">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" Width="432">
<TextBlock x:Name="ItemText" Text="{Binding noteName}" Margin="-2,-13,0,0" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
<TextBlock x:Name="DetailsText" Text="{Binding noteText}" Margin="10,-6,0,3" Style="{StaticResource PhoneTextSubtleStyle}"/>
<TextBlock x:Name="noteIdText" Text="{Binding noteID}" Margin="10,-6,0,3" Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Please someone guide me, thanks. :)
have you tried MainListBox.SelectedItem ?
var data = MainListBox.Selecteditem as [type of class bounded to listbox] ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With