2.0 KiB
2.0 KiB
title | description | type | page_title | slug | position | tags | ticketid | res_type |
---|---|---|---|---|---|---|---|---|
Disable bounce in iOS ListView for Xamarin.Forms | how-to | Disable ListView bounce on iOS Xamarin | listview-ios-disable-bounce | listview, xamarin, ios, disale, bounce, bounces | 1473448 | kb |
Environment
Product Version | 2020.2.624.1 |
Product | ListView for Xamarin Cross-Platform |
Description
The purpose of this article is to show you how to disable the listview bounce on iOS. In addition you can also disable the scrolling.
Solution
The scenario could be achieved using custom renderer for iOS. Create a class inside the iOS project, for example CustomListViewRenderer which inherits from ListViewRenderer. Then override the OnElementchangedMethod and inside it disable the bounces.
Here is the custom renderer implementation:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Foundation;
using ListView.iOS;
using Telerik.XamarinForms.DataControlsRenderer.iOS;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(Telerik.XamarinForms.DataControls.RadListView), typeof(CustomListViewRenderer))]
namespace ListView.iOS
{
public class CustomListViewRenderer : Telerik.XamarinForms.DataControlsRenderer.iOS.ListViewRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Telerik.XamarinForms.DataControls.RadListView> e)
{
base.OnElementChanged(e);
var control = this.Control as TKExtendedListView;
if(control != null)
{
control.Layout.CollectionView.Bounces = false;
// in additiona you can disable the scrolling setting the scrollenabled to false. Check the commented code below:
//control.Layout.CollectionView.ScrollEnabled = false;
}
}
}
}