|
<syncfusion:SfListView x:Name="listView" ItemSpacing="1" AllowSwiping="True" AutoFitMode="Height" SelectionMode="None" ItemsSource="{Binding contactsinfo}">
<syncfusion:SfListView.Behaviors>
<local:EventToCommandBehavior EventName="SwipeStarted" Command="{Binding SwipeStartedCommand}"/>
</syncfusion:SfListView.Behaviors>
<syncfusion:SfListView.ItemTemplate >
<DataTemplate>
<Grid x:Name="grid" BackgroundColor="{Binding BackgroundColor}">
...
</Grid>
</Grid>
</DataTemplate>
</syncfusion:SfListView.ItemTemplate>
...
</syncfusion:SfListView> |
|
public class ContactsViewModel : INotifyPropertyChanged
{
public ObservableCollection<Contacts> contactsinfo { get; set; }
public Command<object> SwipeStartedCommand { get; set; }
private SfListView SfListView;
public ContactsViewModel()
{
contactsinfo = new ObservableCollection<Contacts>();
SwipeStartedCommand = new Command<object>(OnSwipeStarted);
GenerateInfo();
}
private void OnSwipeStarted(object obj)
{
var args = obj as Syncfusion.ListView.XForms.SwipeStartedEventArgs;
if ((args.ItemData as Contacts).BackgroundColor == Color.LightGray)
{
args.Cancel = true;
}
}
} |
|
<syncfusion:SfListView x:Name="listView" ItemSpacing="1" AllowSwiping="True" AutoFitMode="Height" SelectionMode="None" ItemsSource="{Binding contactsinfo}">
<syncfusion:SfListView.Behaviors>
<local:EventToCommandBehavior EventName="SwipeEnded" Command="{Binding SwipeEndedCommand}" CommandParameter="{x:Reference listView}"/>
</syncfusion:SfListView.Behaviors>
<syncfusion:SfListView.ItemTemplate >
<DataTemplate>
...
</DataTemplate>
</syncfusion:SfListView.ItemTemplate>
<syncfusion:SfListView.RightSwipeTemplate>
<DataTemplate>
<Grid BackgroundColor="Black">
<Label Text="Right Swipe" TextColor="White" FontAttributes="Bold" VerticalTextAlignment="Center" HorizontalTextAlignment="Center"/>
<Grid.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Source={RelativeSource AncestorType={x:Type local:ContactsViewModel}}, Path=TakePhotoCommand}" CommandParameter="{Binding .}" />
</Grid.GestureRecognizers>
</Grid>
</DataTemplate>
</syncfusion:SfListView.RightSwipeTemplate>
</syncfusion:SfListView> |
|
public class ContactsViewModel : INotifyPropertyChanged
{
public ObservableCollection<Contacts> contactsinfo { get; set; }
public Command<object> SwipeEndedCommand { get; set; }
public Command<object> TakePhotoCommand { get; set; }
private SfListView SfListView;
public ContactsViewModel()
{
contactsinfo = new ObservableCollection<Contacts>();
SwipeEndedCommand = new Command<object>(OnSwipeEnded);
TakePhotoCommand = new Command<object>(OnTakePhotoClicked);
GenerateInfo();
}
private void OnSwipeEnded(object obj)
{
SfListView = obj as SfListView;
}
private void OnTakePhotoClicked(object obj)
{
SfListView.ResetSwipe();
}
} |
|
<syncfusion:SfListView x:Name="listView" ItemSpacing="1" AllowSwiping="True" AutoFitMode="Height" SelectionMode="None" ItemsSource="{Binding contactsinfo}">
<syncfusion:SfListView.Behaviors>
<local:EventToCommandBehavior EventName="SwipeStarted" Command="{Binding SwipeStartedCommand}"/>
</syncfusion:SfListView.Behaviors>
<syncfusion:SfListView.RightSwipeTemplate>
<DataTemplate>
<Grid BackgroundColor="Black">
<Label Text="Right Swipe" TextColor="White" FontAttributes="Bold" VerticalTextAlignment="Center" HorizontalTextAlignment="Center"/>
<Grid.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Source={RelativeSource AncestorType={x:Type local:ContactsViewModel}}, Path=TakePhotoCommand}" CommandParameter="{x:Reference listView}"/>
</Grid.GestureRecognizers>
</Grid>
</DataTemplate>
</syncfusion:SfListView.RightSwipeTemplate>
</syncfusion:SfListView> |
|
using Syncfusion.ListView.XForms;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace ListViewXamarin
{
public class ContactsViewModel : INotifyPropertyChanged
{
public ObservableCollection<Contacts> contactsinfo { get; set; }
public Command<object> SwipeStartedCommand { get; set; }
public Command<object> TakePhotoCommand { get; set; }
private Contacts SwipedItem;
public ContactsViewModel()
{
contactsinfo = new ObservableCollection<Contacts>();
SwipeStartedCommand = new Command<object>(OnSwipeStarted);
TakePhotoCommand = new Command<object>(OnTakePhotoClicked);
GenerateInfo();
}
private void OnTakePhotoClicked(object obj)
{
//Get the swiped item data from the SwipedItem property.
(obj as SfListView).ResetSwipe(); // Reset swipe
}
private void OnSwipeStarted(object obj)
{
var args = obj as Syncfusion.ListView.XForms.SwipeStartedEventArgs;
this.SwipedItem = args.ItemData as Contacts;
if (SwipedItem.BackgroundColor == Color.LightGray)
{
args.Cancel = true;
}
}
}
} |