I am new to Windows Phone,
I have one listbox with textblocks in it, I want to fetch all data from selected item in listbox.
Here is my code snippet:
.xaml file
<ListBox HorizontalAlignment="Left" Name="listbox1" ItemsSource="{Binding}" Margin="9,10,0,0" SelectionChanged="listBox1_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,5">
<Image HorizontalAlignment="Left" Height="100" Margin="0,15,0,0" VerticalAlignment="Top""/>
<TextBlock Text="{Binding AttractionName}" Foreground="Yellow" Margin="120,-110,0,0""/>
<TextBlock Text="Price:" Foreground="White" TextWrapping="Wrap" FontSize="30""/>
<TextBlock Text="£" Foreground="Green" TextWrapping="Wrap" FontSize="40" Margin="200,-50,12,0""/>
<TextBlock Text="{Binding price}" Foreground="Green" FontSize="40""/>
<Line X1="0" X2="420" Y1="10" Y2="10" Stroke="White" VerticalAlignment="Bottom"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
.cs file
void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs args)
{
Debug.WriteLine(" You selected " +listbox1.SelectedItem.ToString());
}
My console shows output this way: You selected Appname.Pagename.methodname
Class which is bound to ListBox
public class Attractions {
[JsonProperty("AttractionName")]
public string AttractionName { get; set; }
[JsonProperty("IphoneImage")]
public string IphoneImage { get; set; }
[JsonProperty("price")] public string price { get; set; }
}