获取列表框windows phone 7的选定值
本文关键字:phone 列表 windows 获取 | 更新日期: 2023-09-27 18:04:06
我试图获得列表框中选定项目的文本。但是它应该是"System.Windows.Controls.ListBoxItem"的结果
我的代码:
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;