Google Hide Listview scrollbar in Xamarin.Forms (C# - Xaml) | SubramanyamRaju Xamarin & Windows App Dev Tutorials

Wednesday 27 March 2019

Hide Listview scrollbar in Xamarin.Forms (C# - Xaml)

Introduction:
A Xamarin.Forms ListView is a view that displays a collection of data as a vertical list. There are some situations when we want to hide default vertical/horizontal scrollbar for listview in xamarin.forms. So we can learn it from this article.
Requirements:
  • This article source code was prepared by using Visual Studio Professional for Mac (7.6.9). And it is better to install latest visual studio updates from here.
  • This sample project is Xamarin.Forms .NetStandardLibrary project and tested in Android emulator and iOS simulators.
  • Used Xamarin.Forms version is 3.1.0.697729.
Description:
Update: From Xamarin.Forms version 3.5.0, we can use VerticalScrollBarVisibility, HorizontalScrollBarVisibility properties to handle ListView ScrollBarVisibility.

However for older versions, we can hide default ListView scrollbar using custom renderers.
1. Xamarin.Android Project:
In Android project, create a class name is CustomListViewRenderer and make sure to add renderer registration for our ListView class on above of the namespace.
  1. using Xamarin.Forms;  
  2. using HideListViewScroll.Droid.Renderers;  
  3. using Xamarin.Forms.Platform.Android;  
  4.   
  5. [assembly: ExportRenderer(typeof(ListView), typeof(CustomListViewRenderer))]  
  6. namespace HideListViewScroll.Droid.Renderers  
  7. {  
  8.     public class CustomListViewRenderer : ListViewRenderer  
  9.     {  
  10.         protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)  
  11.         {  
  12.             base.OnElementChanged(e);  
  13.   
  14.             if (Control != null)  
  15.             {  
  16.                 Control.VerticalScrollBarEnabled = false;  
  17.                 Control.HorizontalScrollBarEnabled = false;  
  18.             }  
  19.         }  
  20.     }  
  21. }  
2. Xamarin.iOS Project:
In iOS project, create a class name is CustomListViewRenderer and make sure to add renderer registration for our ListView class on above of the namespace.
  1. using System;  
  2. using Xamarin.Forms;  
  3. using Xamarin.Forms.Platform.iOS;  
  4. using System.ComponentModel;  
  5. using HideListViewScroll.iOS.Renderers;  
  6.   
  7. [assembly: ExportRenderer(typeof(ListView), typeof(CustomListViewRenderer))]  
  8. namespace HideListViewScroll.iOS.Renderers  
  9. {  
  10.     public class CustomListViewRenderer : ListViewRenderer  
  11.     {  
  12.         protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)  
  13.         {  
  14.             base.OnElementChanged(e);  
  15.   
  16.             if (Control != null)  
  17.             {  
  18.                 Control.ShowsVerticalScrollIndicator = false;  
  19.                 Control.ShowsHorizontalScrollIndicator = false;  
  20.             }  
  21.         }  
  22.     }  
  23. }  

You can also directly work on below sample source code to understand this article.
HideScrollBar
You can also see overview of this article from below youtube video. Also for more videos please don't forget to SUBSCRIBE our youtube channel from here.


FeedBack Note: Please share your thoughts, what you think about this post, Is this post really helpful for you? I always welcome if you drop comments on this post and it would be impressive.

Follow me always at @Subramanyam_B
Have a nice day by  :)

No comments:

Post a Comment

Search Engine Submission - AddMe