2011-07-30 67 views
1

我想獲取列表框的選定項的文本。 但我應該是「System.Windows.Controls.ListBoxItem」的結果獲取列表框的選擇值Windows Phone 7

我的代碼: listBox.SelectedItem.ToString();

我應該如何更改我的代碼?

+1

在這裏看到:http://stackoverflow.com/questions/6800542/getting-information-from-a-data- binding-listbox-for-a-new-page/6800767#6800767 –

回答

6

試試這個

if(null != listBox.SelectedItem) 
{ 
    string text = (listBox.SelectedItem as ListBoxItem).Content.ToString(); 
} 
+0

感謝您的幫助。 –

0

如果你使用像

public class Person 
    { 

     public string Name; 
     public string LastName; 



    } 

//This class can be in a separate file 


//to create a list from this to fill the listbox you can use the following code. 


//this can be in the interface part of the app where the value of the selecteditem is selected 

Person m = listBoxName.SelectedItem as Person; 

string VariableString = m.Name; 
相關問題