从列表视图中获取文本

我按照这个链接中的教程做了一个自定义列表视图http://www.coderzheaven.com/2012/03/23/how-to-create-a-custom-listbox-in-windows-phone-7/

我的需要是我想获得每行的标题和字幕,当点击一个特定的行。 有没有什么办法让文本没有从它所提供的数组中获取。

public class Account { public string Title { get; set; } public string SubTitle { get; set; } public string ImageUrl { get; set; } } 

MainPage.xaml中

 <ListBox Margin="12,75,12,0" Name="L1" SelectionChanged="ListBox_SelectionChanged"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Margin="0,0,0,17" Width="432" Height="78"> <TextBlock TextWrapping="Wrap" Text="{Binding Title}" Style="{StaticResource PhoneTextExtraLargeStyle}"/> <TextBlock TextWrapping="Wrap" Text="{Binding SubTitle}" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> MainPage.xaml.cs 

公共ObservableCollection MyAccounts {get; 组; }

 public MainPage() { Loaded += MainPageLoaded; } // Load data for the ViewModel Items private void MainPageLoaded(object sender, RoutedEventArgs e) { MyAccounts = GenerateAccounts(); //populate your list L1.ItemsSource = MyAccounts; } private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { var lb = (ListBox)sender; if (lb.SelectedIndex == -1)return; var account = (Account)sender.SelectedItem; //get properties from Account npw. lb.SelectedIndex = -1; } }