Windows phone 7 WP7获取列表框项目文本

Windows phone 7 WP7获取列表框项目文本,windows-phone-7,listbox,Windows Phone 7,Listbox,有没有办法获取单击的列表框项目的文本 因此,单击它将为列表框项目中的文本设置一个字符串。在一个新的数据绑定应用程序中,更改了以下方法以查看三种获取方法: // Handle selection changed on ListBox private void MainListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { // If selected index is -1 (no selection)

有没有办法获取单击的列表框项目的文本


因此,单击它将为列表框项目中的文本设置一个字符串。

在一个新的数据绑定应用程序中,更改了以下方法以查看三种获取方法:

// 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;

    var string1 = ((sender as ListBox).SelectedItem as ItemViewModel).LineOne;
    var string2 = (MainListBox.SelectedItem as ItemViewModel).LineOne;
    var string3 = (e.AddedItems[0] as ItemViewModel).LineOne;

    // 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;
}

在新的DataBound应用程序中,更改了以下方法以查看获取此信息的3种方法:

// 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;

    var string1 = ((sender as ListBox).SelectedItem as ItemViewModel).LineOne;
    var string2 = (MainListBox.SelectedItem as ItemViewModel).LineOne;
    var string3 = (e.AddedItems[0] as ItemViewModel).LineOne;

    // 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;
}

那么,哪个字符串包含文本?
string1
sdtring2
string3
每个字符串都包含文本。很抱歉,有这么多问题,但它知道它在哪一行,我可以使用这三种方法中的任何一种?使用最适合您的方法。我通常会先使用第三个选项并进行空检查:)我是否需要为每一行更改它,或者将这一个代码放入列表框中,它将对所有项目起作用?那么,哪个字符串包含文本?
string1
sdtring2
string3
都包含文本。很抱歉,有这么多问题,它知道它在哪条线上,我可以使用这三种方式中的任何一种?使用最适合你的方式。我通常首先使用第三个选项,并进行空检查:)我是否需要为每一行更改它,或者将这一代码放入列表框中的所有项目中?