Introduction:
A Xamarin.Forms ScrollView contains layouts and enables them to scroll offscreen. There are some situations when we want to hide default vertical/horizontal scrollbar for ScrollView in xamarin.forms. So we can learn it from this article.
Requirements:
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.
A Xamarin.Forms ScrollView contains layouts and enables them to scroll offscreen. There are some situations when we want to hide default vertical/horizontal scrollbar for ScrollView 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.0.0.561731.
Description:
Update: From Xamarin.Forms version 3.1.0, we can use VerticalScrollBarVisibility, HorizontalScrollBarVisibility properties to handle ScrollView ScrollBarVisibility.
However for older versions, we can hide default ScrollView scrollbar using custom renderers.
Update: From Xamarin.Forms version 3.1.0, we can use VerticalScrollBarVisibility, HorizontalScrollBarVisibility properties to handle ScrollView ScrollBarVisibility.
1. Xamarin.Android Project:
In Android project, create a class name is ScrollbarDisabledRenderer and make sure to add renderer registration for our ScrollView class on above of the namespace.
In Android project, create a class name is ScrollbarDisabledRenderer and make sure to add renderer registration for our ScrollView class on above of the namespace.
- using Xamarin.Forms;
- using Xamarin.Forms.Platform.Android;
- using HideScrollViewScroll.Droid.CustomRenderers;
- using System.ComponentModel;
- [assembly: ExportRenderer(typeof(ScrollView), typeof(ScrollbarDisabledRenderer))]
- namespace HideScrollViewScroll.Droid.CustomRenderers
- {
- public class ScrollbarDisabledRenderer : ScrollViewRenderer
- {
- protected override void OnElementChanged(VisualElementChangedEventArgs e)
- {
- base.OnElementChanged(e);
- if (e.OldElement != null || this.Element == null)
- return;
- if (e.OldElement != null)
- e.OldElement.PropertyChanged -= OnElementPropertyChanged;
- e.NewElement.PropertyChanged += OnElementPropertyChanged;
- }
- protected void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
- {
- this.HorizontalScrollBarEnabled = false;
- this.VerticalScrollBarEnabled = false;
- }
- }
- }
2. Xamarin.iOS Project:
In iOS project, create a class name is ScrollbarDisabledRenderer and make sure to add renderer registration for our ScrollView class on above of the namespace.
- using System;
- using Xamarin.Forms;
- using Xamarin.Forms.Platform.iOS;
- using System.ComponentModel;
- using HideScrollViewScroll.iOS.CustomRenderers;
- [assembly: ExportRenderer(typeof(ScrollView), typeof(ScrollbarDisabledRenderer))]
- namespace HideScrollViewScroll.iOS.CustomRenderers
- {
- public class ScrollbarDisabledRenderer : ScrollViewRenderer
- {
- protected override void OnElementChanged(VisualElementChangedEventArgs e)
- {
- base.OnElementChanged(e);
- if (e.OldElement != null || Element == null)
- return;
- if (e.OldElement != null)
- e.OldElement.PropertyChanged -= OnElementPropertyChanged;
- e.NewElement.PropertyChanged += OnElementPropertyChanged;
- }
- private void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
- {
- ShowsHorizontalScrollIndicator = false;
- ShowsVerticalScrollIndicator = false;
- }
- }
- }
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