从C#中的wp7 Listbox获取数据?

时间:2011-07-28 08:09:59

标签: c# windows-phone-7 listbox

C#的新手让我感到困惑。我有这种情况:

   private void result_Click(object sender, RoutedEventArgs e) 
    { 

                   var data = from query in Event.Descendants("event") 
                   select new EventManager 
                   { 
                       name = (string)query.Element("name"), 
                       place = (string)query.Element("place"), 
                       date = (DateTime)query.Element("date"), 
                       time = (DateTime)query.Element("time") 
                   }; 

        myListBox.ItemsSource = data; 
   } 
  1. 如果我想在数组/容器中保存数据?
  2. 如果我想稍后从ListBox中检索数据?

1 个答案:

答案 0 :(得分:0)

您可以设置并稍后像这样获取ItemsSource

List<String> container = new List<String>();
listBox.ItemsSource = container;
List<String> retrieve = (List<String>) listBox.ItemsSource;

就像List一样,你可以拥有任何你想要的容器