问题
How do i create an event for it to detect that the user tapped on the item in listbox
<!--Pivot Control-->
<controls:Pivot Title="MY APPLICATION">
<!--Pivot item one-->
<controls:PivotItem Header="item1">
<ListBox x:Name="lbFiles" HorizontalContentAlignment="Stretch" ItemTemplate="{StaticResource DataTemplate1}">
</ListBox>
</controls:PivotItem>
<!--Pivot item two-->
<controls:PivotItem Header="item2">
</controls:PivotItem>
</controls:Pivot>
Code behind
private void lbFile_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
selected = lbFiles.SelectedItem.ToString();
general item = new general();
item.viewimage(selected);
NavigationService.Navigate(new Uri("/View.xaml", UriKind.Relative));
}
headache THanks! :D
回答1:
You're not attaching the SelectionChanged event. You have a function for it there, but you're not making anything use it.
<ListBox x:Name="lbFiles" HorizontalContentAlignment="Stretch" SelectionChanged="lbfile_SelectionChanged" ItemTemplate="{StaticResource DataTemplate1}">
</ListBox>
You need to attach events so that they are used. You should go through the first few WP7 tutorials on create.msdn - you'll find a lot of what you need to get started and feel more comfortable about things like this.
来源:https://stackoverflow.com/questions/9053420/tap-gesture-as-select-for-listbox