A Simple Code to Hide the Scroll Bar in Listview of Xamarin.Forms

xam-forms-awesomelistview

Hello peeps, I am back again with a new and amazing Xamarin app development coding trick which you guys can use in a way to hide the scrolling bar in the Listview of your mobile application which you are building using the Xamarin.Forms. To make the code easy to understand and implement, I am pen down the code procedure in a step by step format.

Step 1.

As in the first step towards the implementation of the code, create a class in PCL/.NET standard and share the projectwith a new name.

Just like, here I am creating a class in my code file with a name as “MyListview”.

using Xamarin.Forms;

namespace MyListViewDemo {

public class CustomListview: ListView {}

}

Step 2.

Now, for the second step, I am creating a renderer code for the Xamarin.Android Platform.

using Android.Content;

using MyListViewDemo;

using MyListViewDemo.Droid;

using Xamarin.Forms;

using Xamarin.Forms.Platform.Android;

[assembly: ExportRenderer(typeof(MyListview), typeof(myListViewRenderer))]

namespace MyListViewDemo.Droid {

public class MyListViewRenderer: ListViewRenderer {

Context _context;

public MyListViewRenderer(Context context): base(context) { _context = context;  }

Protected override void OnElementChanged(ElementChangedEventArgs < Xamarin.Forms.ListView > e) { base.OnElementChanged(e);

if (Control != null) {

Control.VerticalScrollBarEnabled = false;

}

}

}

}

Step 3.

Likewise, Android renderer code, now I am developing a renderer code for Xamarin.iOS platform.

using MyListViewDemo.iOS;

using Xamarin.Forms;

using Xamarin.Forms.Platform.iOS;

using MyListViewDemo;

[assembly: ExportRenderer(typeof(MyCustomListview), typeof(MyListViewRenderer))]

namespace MyListViewDemo.iOS {

public class MyListViewRenderer: ListViewRenderer {

protected override void OnElementChanged(ElementChangedEventArgs < ListView > e) {

base.OnElementChanged(e);

if (Control != null) {

Control.ShowsVerticalScrollIndicator = false;

}

}

}

Step 4.

In the form of final step, we need to use this newly-developed renderer code in the project. For this intention, we need to follow a simple procedure as follows:

Import the namespace into XAML, use the code below.

xmlns:local=”clr-namespace:MyListViewDemo”

If you need to add a custom control, simply use this code:

<local:CustomListview></local:CustomListview>

Finally add the code in XAML page:

<?xml version=”1.0″ encoding=”utf-8″ ?>

<ContentPage xmlns=”http://xamarin.com/schemas/2014/forms” xmlns:x=”http://schemas.microsoft.com/winfx/2009/xaml” xmlns:local=”clr-namespace:MyListViewDemo” x:Class=”MyListViewDemo.MainPage”>

<StackLayout HorizontalOptions=”FillAndExpand” VerticalOptions=”FillAndExpand”>

<local:MyListview></local:MyListview>

</StackLayout>

</ContentPage>

by admin

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>