[英]Adding a single item to a ListView in Xamarin.iOS
I have a Xamarin.iOS application with a ListView in a .xaml file that originally populates with around 4000 items (potentially more) from a DB at startup. 我有一个Xamarin.iOS应用程序,该应用程序在.xaml文件中具有ListView,该文件最初在启动时从数据库中填充了大约4000项(可能更多)。
<ListView x:Name="listView"></ListView>
The user will make entries in another page of the application while it's open, so I want to add a function in the .xaml.cs file to update the ListView with only that entry so the other 4000 entries don't have to be accessed again. 用户将在打开该应用程序的另一个页面时在该页面上创建条目,因此我想在.xaml.cs文件中添加一个函数以仅使用该条目来更新ListView,因此不必再次访问其他4000个条目。
Setting all the items in a ListView with a string[]
or List<string>
is simple with listView.ItemsSource = myStringArray;
使用
string[]
或List<string>
设置ListView中的所有项目很简单, listView.ItemsSource = myStringArray;
使用listView.ItemsSource = myStringArray;
; ; however, I can't seem to figure out how to add a single item (string) into the ListView.
但是,我似乎无法弄清楚如何向ListView中添加单个项目(字符串)。 Some answers include using an
ArrayAdaptor<string>
but this is only for Xamarin.Android. 一些答案包括使用
ArrayAdaptor<string>
但这仅适用于Xamarin.Android。 How can I add one string into a ListView in Xamarin.iOS? 如何在Xamarin.iOS的ListView中添加一个字符串?
ObservableCollection<string> data = new ObservableCollection<string>();
// do something to populate data with an initial dataset
MyListView.ItemsSource = data;
// to add an item to the ListView, add it to the ItemsSource
data.Add("my new item");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.