2X faster development
The ultimate Xamarin UI toolkit to boost your development speed.
The SfCardView is a Syncfusion UI component that helps organizing the content in UI views as cards. This section explains how to remove a card from Xamarin.Forms CardView collection. You can remove the cards by enabling the SwipeToDismiss property in CardView.
Consider, the use case of showing a list of social media applications in a Xamarin.Forms application as follows.
Creating the previous UI
You can achieve the previous UI using the following code snippets:
[XAML] .. <ListView x:Name="EventListView" RowHeight="100" SeparatorVisibility="None" ItemsSource="{Binding Items}"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <cards:SfCardView Dismissed="SfCardView_Dismissed" SwipeToDismiss="True" Margin="10"> <Grid HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"> <StackLayout Orientation="Horizontal" > <Image Margin="10,0,0,0" HeightRequest="40" WidthRequest="40" Source="{Binding Image}"/> <Label FontAttributes="Bold" Margin="10,0,0,0" FontSize="16" MaxLines="1" Text="{Binding Title}" LineBreakMode="NoWrap" TextColor="Black" HorizontalOptions="Start" VerticalOptions="Center" /> </StackLayout> </Grid> </cards:SfCardView> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView>
[C#] public class CardModel { public string Title {get; set;} public string Image {get; set;} }
[C#]
public class CardViewModel { public ObservableCollection<CardModel> Items { get; set; } public CardViewModel() { Items = new ObservableCollection<CardModel>() { new CardModel(){ Title = "Facebook" , Image = "FacebookFill.png"}, new CardModel(){ Title = "Gmail" , Image = "GmailFill.png"}, new CardModel(){ Title = "Instagram" , Image = "InstagramFill.png"}, new CardModel(){ Title = "WhatsApp" , Image = "WhatsappFill.png"}, }; } }
[C#] public MainPage() { InitializeComponent(); items = (BindingContext as CardViewModel)?.Items; }
Since, we have added that CardView in a ListView, even though it is been removed from CardView collection still exists in the ListView. So, to remove it thoroughly, we have removed that model in the Dismissed event as shown in the following code snippet.
[C#]
You can get the complete sample from this GitHub location.
See Also
How to dismiss the cards programmatically
|
2X faster development
The ultimate Xamarin UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.