开发者

Adding a new item to ListBox.ItemsSource

开发者 https://www.devze.com 2023-02-28 15:27 出处:网络
I\'m developing a Windows Phone app. I have a listbox with this C# source code: System.Collections.Generic.IEnumerable<OpenGame> items;

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消