2011-06-20 169 views

回答

4

在一個新的數據綁定應用程序,改變了下面的方法看看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; 
} 
+0

那麼字符串包含的文本? – Al3xhamilton

+1

'string1','sdtring2'和'string3'每個都包含文本。 –

+0

對不起,有這麼多的問題,但是它知道什麼線路,我可以使用3種方式中的任何一種? – Al3xhamilton