Hello, I need some advice. I'm trying to create my own SfListView render for android and I need to disable OverScrollMode. How can I achieve this? I followed this guide https://www.syncfusion.com/kb/11398/how-to-use-custom-renderer-for-listview-in-xamarin-forms-sflistview how to create custom render for SfListView but in render for android OverScrollMode is not accessible. Thanks a lot.
[assembly: ExportRenderer(typeof(ExtendedListView), typeof(SfListViewControlRenderer))]
[assembly: ExportRenderer(typeof(ExtendedListView), typeof(MaterialSfListViewRenderer), new[] { typeof(VisualMarker.MaterialVisual) })]
namespace Syncfusion.ListView.XForms.Android
{
internal class SfListViewControlRenderer : VisualElementRenderer<SfListView>
{
/// <summary>
/// Actual visual of the control.
/// </summary>
protected IVisual ActualVisual = VisualMarker.Default;
internal SfListView ListView
{
get
{
return this.Element as SfListView;
}
}
public SfListViewControlRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<SfListView> e)
{
if (this.Element != null)
Element.BackgroundColor = Color.LightPink; //Set Background color for ListView
base.OnElementChanged(e);
}
}
internal class MaterialSfListViewRenderer : SfListViewControlRenderer
{
public MaterialSfListViewRenderer(Context context) : base(context)
{
this.ActualVisual = VisualMarker.Material;
}
}
}
Hi Václav,
The OverScrollMode is available in the native view, and you can achieve your requirement by using the dependency service.
Please refer to the following code snippets for more reference,
Write dependency interface in the PCL project.
|
public interface IDependencyServiceListView { void DisableOverScrollMode(SfListView ListView); } |
Implement the interface and get the ExtendedScrollViewRenderer. You can access the OverScrollMode from the ExtendedScrollViewRenderer.View property.
|
[assembly: Dependency(typeof(ListViewDependencyService))] namespace ListViewXamarin.Droid { public class ListViewDependencyService : IDependencyServiceListView { ExtendedScrollView ExtendedScrollView;
public void DisableOverScrollMode(SfListView ListView) { ExtendedScrollView = ListView.GetScrollView(); var extendedScrollViewRenderer = Platform.GetRenderer(ExtendedScrollView); extendedScrollViewRenderer.View.OverScrollMode = OverScrollMode.Never; } } } |
In the OnAppearing override, call the dependency method for the ListView to update the API.
|
protected override void OnAppearing() { base.OnAppearing();
if (Device.RuntimePlatform == Device.Android) { DependencyService.Get<IDependencyServiceListView>().DisableOverScrollMode(listView); } } |
We have prepared a sample for the same and you can download it from the attachment.
Please let us know if you need further assistance.
Regards,
Lakshmi Natarajan