#Xamarin #SwipeView in a ListView

gestures-tap-swipe.pngOnce you’ve upgraded to at least Xamarin 4.4, you can use the new SwipeView to easily add Swiping. If you have an older app with ListViews that haven’t yet been upgraded to the CollectionView, you can still use SwipeViews. Here’s how to retrofit:

In your iOS project add this to the Finished Launching before the Forms Init()

public override bool FinishedLaunching(UIApplication appNSDictionary options)
{
 
	Forms.SetFlags("SwipeView_Experimental");
	global::Xamarin.Forms.Forms.Init();

In your Android MainActivity add:

protected override void OnCreate(Bundle bundle)
{
	Forms.SetFlags("SwipeView_Experimental");

Now, open your Cell.xaml ContentView used by your ListView and wrap the full ContentView.Content in a SwipeView:

	<ContentView.Content>
 
	<SwipeView android:SwipeView.SwipeTransitionMode="Drag"        
                    ios:SwipeView.SwipeTransitionMode="Drag">
		<SwipeView.LeftItems>
			<SwipeItems>
				<SwipeItem Text="Favorite"
					   IconImageSource="listviewcell_opportunity.png"
					   BackgroundColor="LightGreen"
					 />
				<SwipeItem Text="Delete"
					  IconImageSource="listviewcell_opportunity.png"
					  BackgroundColor="LightPink"
					  />
			</SwipeItems>
		</SwipeView.LeftItems>

Your content here then close it up:

	  </SwipeView> 
  </ContentView.Content>

Then you’ll be able to swipe!

2020-01-16 11_46_53-Window.png

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s