列表框项目单击事件?

Sra*_*nti 5 windows-phone-7

我将一些项目绑定到列表框.每当点击特定的列表项目时,我想在另一个页面中显示该子项目.

请告诉我如何实现这一目标.

如何在点击特定列表项时获取listitem id?

Hen*_*y C 28

为了澄清(如果您不想创建新的DataBound应用程序并且只想要答案),您应该查看列表框本身的selectionchanged事件,而不是依赖于列表框项目的click事件.

例如:

<ListBox SelectionChanged="MainListBox_SelectionChanged">


// Handle selection changed on ListBox
private void MainListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    // If selected index is -1 (no selection) do nothing
    if (MainListBox.SelectedIndex == -1)
        return;

    // Navigate to the new page
    NavigationService.Navigate(new Uri("/DetailsPage.xaml?selectedItem=" + MainListBox.SelectedIndex, UriKind.Relative));

    // Reset selected index to -1 (no selection)
    MainListBox.SelectedIndex = -1;
}
Run Code Online (Sandbox Code Playgroud)


Mat*_*cey 2

查看作为新 DataBound 应用程序的一部分创建的代码。它就是这样做的。