【问题标题】:Getting selected value of listbox windows phone 7获取列表框windows phone 7的选定值
【发布时间】:2014-07-21 07:15:37
【问题描述】:

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

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

我应该如何更改我的代码?

【问题讨论】:

标签: c# windows-phone-7


【解决方案1】:

试试这个

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

【讨论】:

    【解决方案2】:

    如果你使用像

    这样的类
        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;
    

    【讨论】:

      猜你喜欢
      • 2011-10-29
      • 1970-01-01
      • 2012-05-30
      • 1970-01-01
      • 1970-01-01
      • 2011-11-05
      • 2011-03-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多