|
2 | 2 |
|
3 | 3 | This example demonstrates how to swipe an item programmatically in xamarin.forms listview. |
4 | 4 |
|
| 5 | +## Sample |
| 6 | + |
| 7 | +```xaml |
| 8 | +<StackLayout> |
| 9 | + <Grid HeightRequest="50"> |
| 10 | + <Button x:Name="RightSwipe" Text="Right Swipe Button" /> |
| 11 | + <Button x:Name="LeftSwipe" Text="Left Swipe Button" Grid.Column="1"/> |
| 12 | + </Grid> |
| 13 | + <listView:SfListView x:Name="listView" ItemSize="70" SelectionMode="Single" AllowSwiping="True" ItemSpacing="0,0,5,0" > |
| 14 | + |
| 15 | + <listView:SfListView.LeftSwipeTemplate> |
| 16 | + <DataTemplate> |
| 17 | + <ViewCell> |
| 18 | + <ViewCell.View> |
| 19 | + <Grid BackgroundColor="SlateBlue" HorizontalOptions="Fill" VerticalOptions="Fill"> |
| 20 | + <Label Text="Left Swipe Template" TextColor="White" VerticalOptions="Center" HorizontalOptions="Center"/> |
| 21 | + </Grid> |
| 22 | + </ViewCell.View> |
| 23 | + </ViewCell> |
| 24 | + </DataTemplate> |
| 25 | + </listView:SfListView.LeftSwipeTemplate> |
| 26 | + |
| 27 | + <listView:SfListView.RightSwipeTemplate> |
| 28 | + <DataTemplate> |
| 29 | + <ViewCell> |
| 30 | + <ViewCell.View> |
| 31 | + <Grid BackgroundColor="SlateBlue" HorizontalOptions="Fill" VerticalOptions="Fill"> |
| 32 | + <Label Text="Right Swipe Template" TextColor="White" VerticalOptions="Center"/> |
| 33 | + </Grid> |
| 34 | + </ViewCell.View> |
| 35 | + </ViewCell> |
| 36 | + </DataTemplate> |
| 37 | + </listView:SfListView.RightSwipeTemplate> |
| 38 | + |
| 39 | + <listView:SfListView.ItemTemplate> |
| 40 | + <DataTemplate> |
| 41 | + <ViewCell> |
| 42 | + <ViewCell.View> |
| 43 | + <code> |
| 44 | + . . . |
| 45 | + . . . |
| 46 | + <code> |
| 47 | + </ViewCell.View> |
| 48 | + </ViewCell> |
| 49 | + </DataTemplate> |
| 50 | + </listView:SfListView.ItemTemplate> |
| 51 | + </listView:SfListView> |
| 52 | +</StackLayout> |
| 53 | + |
| 54 | +Code Behind : |
| 55 | +Button rightSwipeButton = bindable.FindByName<Button>("RightSwipe"); |
| 56 | +Button leftSwipeButton = bindable.FindByName<Button>("LeftSwipe"); |
| 57 | +rightSwipeButton.Clicked += RightSwipeButton_Clicked; |
| 58 | +leftSwipeButton.Clicked += LeftSwipeButton_Clicked; |
| 59 | + |
| 60 | +private void LeftSwipeButton_Clicked(object sender, EventArgs e) |
| 61 | +{ |
| 62 | + ListView.SwipeItem(viewModel.contactsinfo[1], 200); |
| 63 | +} |
| 64 | + |
| 65 | +private void RightSwipeButton_Clicked(object sender, EventArgs e) |
| 66 | +{ |
| 67 | + ListView.SwipeItem(viewModel.contactsinfo[1], -150); |
| 68 | +} |
| 69 | +``` |
| 70 | + |
5 | 71 | ## Requirements to run the demo |
6 | 72 |
|
7 | 73 | * [Visual Studio 2017](https://visualstudio.microsoft.com/downloads/) or [Visual Studio for Mac](https://visualstudio.microsoft.com/vs/mac/) |
|
0 commit comments