0

I'm developing a Windows Phone app.

I have a listbox with this C# source code:

System.Collections.Generic.IEnumerable<OpenGame> items;

...

GamesList.ItemsSource = items;

If I want to add a new item (a new OpenGame object) to the GameList, how can I do it?

VansFannel
  • 45,055
  • 107
  • 359
  • 626

2 Answers2

6

Use ObservableCollection rather than IEnumerable then you can use the Add method.

IEnumerable is for static lists where you don't want to add or remove members.

ObservableCollection is designed for lists bound to ListBoxes and similar controls. As well as allowing you to add and remove items it will notify the list box so it gets updated when the collection changes.

Steve Chadbourne
  • 6,873
  • 3
  • 54
  • 82
0

I think you can find you're answer with explanations in this thread: How can I add an item to a IEnumerable<T> collection?

Community
  • 1
  • 1
ChristiaanV
  • 5,401
  • 3
  • 32
  • 42