Reputation: 576
I want to access the text content after binding of the "GameName" textblock that is inside the listbox.
<controls:PanoramaItem Header="games" Margin="0" Height="800" Foreground="White" VerticalAlignment="Center">
<!--Double line list with text wrapping-->
<ListBox x:Name="GamesListBox" Margin="0,0,-12,66" Height="614" ItemsSource="{Binding dataFeed}" SelectionChanged="GamesListBox_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,0,0,17">
<!--Replace rectangle with image-->
<Image Height="100" Width="100" Source="{Binding AllGamesImage}" Margin="12,0,9,0" VerticalAlignment="Top" HorizontalAlignment="Left" Stretch="UniformToFill" />
<StackPanel Width="311">
<TextBlock x:Name="GameName" Text="{Binding AllGamesTitle}" TextWrapping="Wrap" Foreground="White" Style="{StaticResource PhoneTextExtraLargeStyle}" Margin="0,0,0,1"/>
<TextBlock Text="{Binding AllGamesDescription}" TextWrapping="Wrap" Margin="0,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</controls:PanoramaItem>
i want to take whatever is set as the text content and pass it to another page as a parameter or anything.
code behind after Shawn Kendrot suggestion.
private void GamesListBox_SelectionChanged(object sender, EventArgs e)
{
var myObject = GamesListBox.SelectedItem as NewGamesClass;
string gameName = myObject.TitleCode;
NavigationService.Navigate(new Uri("/Pages/AchivementListPage.xaml?gameName=" + gameName, UriKind.Relative));
}
i get a NullExeception when returing to the page here:
string gameName = myObject.TitleCode;
Upvotes: 0
Views: 162
Reputation: 2085
Try this
ListBoxItem selItem = (ListBoxItem)(listboxWeight.ItemContainerGenerator.ContainerFromIndex(listboxWeight.SelectedIndex));
StackPanel weightpanel = (StackPanel)selItem.Content;
var child1 = weightpanel.Children[0] as TextBlock;
var child2 = weightpanel.Children[1] as TextBlock;
Upvotes: 0
Reputation: 12465
Why access the Text property when you can access the property of the object?
void GamesListBox_SelectionChanged(object sender, EventArgs e)
{
var myObject = GamesListBox.SelectedItem as MyObject;
string gameName = myObject.AllGamesTitle;
// Do something with gameName
}
Upvotes: 3