I have my custom renderer for the ListView control and the intention is that the scrollbar is always displayed.
According to the Android documention this can be done;
https://developer.android.com/reference/android/view/View#setVerticalScrollBarEnabled(boolean)
However my custom control does not do this as intended. The Scrollbar behaves as before, not visible unless a ListView item is selected.
What am I doing wrong?
<c:ListViewScrollBar ItemsSource="{Binding PropertyList}"> <c:ListViewScrollBar.Behaviors> <b:EventToCommandBehavior Command="{Binding ItemTappedCommand}" EventName="ItemTapped" EventArgsParameterPath="Item" /> </c:ListViewScrollBar.Behaviors> <c:ListViewScrollBar.ItemTemplate> <DataTemplate> <ViewCell> <ContentView Padding="3"> <Label Text="{Binding FullAddress}" BackgroundColor="blue" TextColor="White" FontSize="7" VerticalTextAlignment="Center" HorizontalTextAlignment="Center" /> </ContentView> </ViewCell> </DataTemplate> </c:ListViewScrollBar.ItemTemplate> </c:ListViewScrollBar>
using Xamarin.Forms;
namespace Sir.Mobile.CustomRenderers
{
public class ListViewScrollBar : ListView
{
public ListViewScrollBar()
{
}
}
}
using Android.Content;
using Sir.Mobile.CustomRenderers;
using Sir.Mobile.Droid.CustomRenderers;
using System.ComponentModel;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(ListViewScrollBar), typeof(ListViewScrollBarRenderer))]
namespace Sir.Mobile.Droid.CustomRenderers
{
/// <inheritdoc />
public class ListViewScrollBarRenderer : ListViewRenderer
{
public ListViewScrollBarRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.VerticalScrollBarEnabled = true;
}
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (Control != null)
{
Control.VerticalScrollBarEnabled = true;
}
}
}
}