获取列表框windows phone 7的选定值

时间:2011-07-30 14:58:18

标签: c# windows-phone-7

我正在尝试获取列表框中所选项目的文本。 但我应该是“System.Windows.Controls.ListBoxItem”

的结果

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

我该如何更改我的代码?

2 个答案:

答案 0 :(得分:6)

试试这个

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

答案 1 :(得分: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;