我想獲取列表框的選定項的文本。 但我應該是「System.Windows.Controls.ListBoxItem」的結果獲取列表框的選擇值Windows Phone 7
我的代碼: listBox.SelectedItem.ToString();
我應該如何更改我的代碼?
我想獲取列表框的選定項的文本。 但我應該是「System.Windows.Controls.ListBoxItem」的結果獲取列表框的選擇值Windows Phone 7
我的代碼: listBox.SelectedItem.ToString();
我應該如何更改我的代碼?
試試這個
if(null != listBox.SelectedItem)
{
string text = (listBox.SelectedItem as ListBoxItem).Content.ToString();
}
感謝您的幫助。 –
如果你使用像
類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;
在這裏看到:http://stackoverflow.com/questions/6800542/getting-information-from-a-data- binding-listbox-for-a-new-page/6800767#6800767 –