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;
开发者_StackOverflow社区
If I want to add a new item (a new OpenGame object) to the GameList, how can I do it?
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.
I think you can find you're answer with explanations in this thread: How can I add an item to a IEnumerable<T> collection?
精彩评论