Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can We Hide Scrollbar in ScrollView Xamarin.Forms

As stated at the title

Is it possible to hide the scrollbar in ScrollView Xamarin.Forms without having to create a custom renderer for each platform?

I can't seem to find any answers, suggestions, or examples that are not using custom renderer.

like image 291
Akaya93 Avatar asked Dec 17 '15 10:12

Akaya93


People also ask

How do I make StackLayout scrollable?

Scrolling content If a StackLayout contains too many children to display on a page, you can put the StackLayout in a ScrollView to allow scrolling. Set the Content property of ScrollView to the view you want to scroll. This is often a StackLayout , but it can be any view.

What is ScrollView in xamarin forms?

ScrollView is a layout that's capable of scrolling its content. The ScrollView class derives from the Layout class, and by default scrolls its content vertically. A ScrollView can only have a single child, although this can be other layouts. Warning.

How do I hide scrollbar in flutter Web?

You can use ScrollConfiguration widget to pass a spesific scroll behaviour to the widget tree. ScrollConfiguration( behavior: ScrollConfiguration. of(context). copyWith(scrollbars: false), child: ListView(...) )


Video Answer


2 Answers

edit Mar 7, 2018: for Googleability: a PR was merged which adds this ability to the default Xamarin.Forms toolkit. It should be released in the NuGets soon.

Original answer:

As stated in the comments you are not able to achieve this without the use of a CustomRenderer.

Create a class ScrollViewExRenderer in your iOS and Droid project and put this in it, the code taken from the link in the comments as well;

public class ScrollViewExRenderer : 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)
    {
        if (ChildCount > 0)
        {
            GetChildAt(0).HorizontalScrollBarEnabled = false;
            GetChildAt(0).VerticalScrollBarEnabled = false;
        }
    }
} 

Above the namespace declaration put this line;

[assembly: ExportRenderer(typeof(ScrollView), typeof(ScrollViewExRenderer))]

Now your ScrollViews should not show any scrollbars

like image 188
Gerald Versluis Avatar answered Oct 06 '22 00:10

Gerald Versluis


Hey this seems a bit late to post an answer but since you haven't selected an answer i will post the procedure for android and windows projects. The answer given by gerald might have been true at some point but i couldn't get it to work maybe because xamarin has changed a lot.

Create a new class in .DROID and .UWP projects and add the following code

For .UWP

using Windows.UI.Xaml.Controls;
using System.ComponentModel;
using Xamarin.Forms;
using Xamarin.Forms.Platform.UWP;

[assembly: ExportRenderer(typeof(ScrollView), typeof(App3.UWP.Scrollbardisabledrenderer))]

namespace App3.UWP
{
    public class Scrollbardisabledrenderer : ScrollViewRenderer
    {
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {


            Control.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
            Control.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;

        }


    }

}

For .DROID

using System.ComponentModel;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;



[assembly: ExportRenderer(typeof(ScrollView), typeof(App3.Droid.Scrollbardisabledrenderer))]

namespace App3.Droid
{
    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;



        }
    }
}

I'm sorry about .IOS I can't confirm whether my code is working or not because I dont have a mac.

like image 20
Zany Avatar answered Oct 06 '22 00:10

Zany