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:
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.
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.
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.
- using Xamarin.Forms;
- using HideListViewScroll.Droid.Renderers;
- using Xamarin.Forms.Platform.Android;
- [assembly: ExportRenderer(typeof(ListView), typeof(CustomListViewRenderer))]
- namespace HideListViewScroll.Droid.Renderers
- {
- public class CustomListViewRenderer : ListViewRenderer
- {
- protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
- {
- base.OnElementChanged(e);
- if (Control != null)
- {
- Control.VerticalScrollBarEnabled = false;
- Control.HorizontalScrollBarEnabled = false;
- }
- }
- }
- }
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.
- using System;
- using Xamarin.Forms;
- using Xamarin.Forms.Platform.iOS;
- using System.ComponentModel;
- using HideListViewScroll.iOS.Renderers;
- [assembly: ExportRenderer(typeof(ListView), typeof(CustomListViewRenderer))]
- namespace HideListViewScroll.iOS.Renderers
- {
- public class CustomListViewRenderer : ListViewRenderer
- {
- protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
- {
- base.OnElementChanged(e);
- if (Control != null)
- {
- Control.ShowsVerticalScrollIndicator = false;
- Control.ShowsHorizontalScrollIndicator = false;
- }
- }
- }
- }
You can also directly work on below sample source code to understand this article.
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.
No comments:
Post a Comment