I'm new to XAML and Windows Phone 7 SDK. I'm developing an Windows Phone 7 application and I don't know how to detect selected item from the ListBox. I'm using panorama template, here is my code:
<controls:PanoramaItem Header="Basic">
<ListBox Margin="0,0,-12,0" Name="MyListBox" SelectionChanged="Elementary_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,0,0,17">
<Image Height="100" Width="100" Source="{Binding LevelPassedImage}" Margin="12,0,9,0"/>
<StackPanel Width="311">
<TextBlock Name="lvlName" x:Uid="Elementary{Binding LevelId}" Text="{Binding LevelName}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}" />
<TextBlock Text="{Binding LevelPassed}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</controls:PanoramaItem>
And C# code:
MessageBox.Show(Elementary.SelectedItem.ToString()); //returns "LocalXmlParsing.XMLParser"
I'm using XMLParser, app initialization code:
var parser = LocalXmlParsing.XMLParser.Instance;
StreamResourceInfo strm = Application.GetResourceStream(new Uri("Levels/ElementaryLevels.xml", UriKind.Relative));
StreamReader reader = new StreamReader(strm.Stream);
string data = reader.ReadToEnd();
parser.DataToParse = data;
parser.ParseStateData();
MyListBox.ItemsSource = parser.LevelCollection;
When I'm trying to detect SelectedItem
, ListBox returns me this string: "LocalXmlParsing.XMLParser".