I want to add items to a ListView with .NET 7 + C#. Is there a way to do this programmatically with C#? The reason is the app will receive data from a server and I want to add parts of the data to the listview.
I have read this https://learn.microsoft.com/en-us/do.net/maui/user-interface/controls/listview?view.net-maui-7.0 but there is no information on how to do this with C# completely, neither is there anything I can find on Google (except by installing packages, which I want to avoid). Maybe I am misunderstanding something.
I would appreciate an example.
the ListView
gets its data from its ItemsSource
, which is an IEnumerable
. To add data dynamically, just Add
elements to the data source
ObservableCollection<string> myData = new ObservableCollection<string>();
MyListView.ItemsSource = myData;
...
myData.Add("new item");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.