XAML:
<Grid>
<Button Text="Add Item" Command="{Binding TapCommand}" CommandParameter="{x:Reference listView}"/>
<syncfusion:SfListView/>
</Grid>
ViewModel:
public class ContactsViewModel : INotifyPropertyChanged
{
public Command<object> TapCommand { get; set; }
public ContactsViewModel()
{
contactsinfo = new ObservableCollection<Contacts>();
TapCommand = new Command<object>(OnTapped);
}
private void OnTapped(object obj)
{
listView = obj as SfListView;
Contacts newContact = new Contacts();
newContact.ContactName = "Jonas";
contactsinfo.Add(newContact);
int newIndex = listView.DataSource.DisplayItems.IndexOf(newContact);
listView.LayoutManager.ScrollToRowIndex(newIndex, true);
}
}
|