<sync:SfListView x:Name="listView" ItemsSource="{Binding BookInfo}">
<sync:SfListView.IsScrollBarVisible>
<OnPlatform x:TypeArguments="x:Boolean">
<OnPlatform.Android>
<OnIdiom x:TypeArguments="x:Boolean" Phone="false" Tablet="false"/>
</OnPlatform.Android>
<OnPlatform.iOS>
<OnIdiom x:TypeArguments="x:Boolean" Phone="false" Tablet="false"/>
</OnPlatform.iOS>
<OnPlatform.WinPhone>
<OnIdiom x:TypeArguments="x:Boolean" Phone="true" Tablet="true"/>
</OnPlatform.WinPhone>
</OnPlatform>
</sync:SfListView.IsScrollBarVisible>
</sync:SfListView> |
Hi,Thank you for using Syncfusion Products.In SfListView, we have property “IsScrollBarVisible” for achieve your requirement “Enable/disable the ScrollBar visibility in ListView”, no need to create renderer for this. By default, the IsScrollBarVisible property value is true. You can enable/disable the scrollbar visibility for specific platforms as like below code example.Code Example[XAML]:
<sync:SfListView x:Name="listView" ItemsSource="{Binding BookInfo}"><sync:SfListView.IsScrollBarVisible><OnPlatform x:TypeArguments="x:Boolean"><OnPlatform.Android><OnIdiom x:TypeArguments="x:Boolean" Phone="false" Tablet="false"/></OnPlatform.Android><OnPlatform.iOS><OnIdiom x:TypeArguments="x:Boolean" Phone="false" Tablet="false"/></OnPlatform.iOS><OnPlatform.WinPhone><OnIdiom x:TypeArguments="x:Boolean" Phone="true" Tablet="true"/></OnPlatform.WinPhone></OnPlatform></sync:SfListView.IsScrollBarVisible></sync:SfListView>For your reference, we have attached the sample and you can download the same from the below location.Limitation:· Due to some restrictions in native ScrollView renderer in Xamarin Forms, you cannot change the IsScrollBarVisible property at runtime. It can be defined only while initializing the SfListView.Please let us know if you require further assistance.Regards,G.Muthu Kumaran.
Doing this would affect the scrolling of the ListView but interaction like selection would still work out. You can't view the items below the viewport area.
[assembly: ExportRenderer(typeof(SfListView), typeof(CustomSfListViewRenderer))]
namespace XamarinSfListViewDemo.Droid
{
public class CustomSfListViewRenderer : ViewRenderer<SfListView,Android.Views.View>
{
private Xamarin.Forms.ScrollView scroller;
protected override void OnElementChanged(ElementChangedEventArgs<SfListView> e)
{
base.OnElementChanged(e);
var element = e.NewElement;
scroller = (Xamarin.Forms.ScrollView)typeof(SfListView).GetField("scrollView", BindingFlags.NonPublic)
.GetValue(element);
scroller.InputTransparent = true;
}
}
}
I haven't tried this code in iOS but 90% it should work. Give it a try and let me know whether it helps!
[assembly: ExportRenderer(typeof(SfListView), typeof(CustomSfListViewRenderer))]
namespace ListViewSample.Droid
{
public class CustomSfListViewRenderer : ViewRenderer<SfListView, Android.Views.View>
{
private Xamarin.Forms.ScrollView scroller;
protected override void OnElementChanged(ElementChangedEventArgs<SfListView> e)
{
base.OnElementChanged(e);
var element = e.NewElement;
scroller = element.GetType().GetField("scrollView", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(element) as ExtendedScrollView;
scroller.InputTransparent = true;
}
}
} |
Raise of "null reference exception" is due to the Element type which you're referencing, SfListViewWithNoScroll which doesn't have a direct element called scrollView. So Instead of this line : scroller = element.GetType().GetField("scrollView", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(element) as ExtendedListView;Use:scroller = typeof(SfListView).GetField("scrollView", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(element) as ScrollView;
<ContentPage.Resources>
<ResourceDictionary>
<local:KeyToValueConverter x:Key="KeyTovalueConverter"/>
</ResourceDictionary>
</ContentPage.Resources>
<listView:SfListView x:Name="listView" ItemsSource="{Binding contactsinfo}" AllowGroupExpandCollapse="True">
<listView:SfListView.DataSource >
<dataSource:DataSource>
<dataSource:DataSource.GroupDescriptors>
<dataSource:GroupDescriptor PropertyName="UserId"/>
</dataSource:DataSource.GroupDescriptors>
</dataSource:DataSource>
</listView:SfListView.DataSource>
<listView:SfListView.GroupHeaderTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<Label Text="{Binding Items, Converter={StaticResource KeyTovalueConverter}}" HorizontalOptions="Start"
Margin="0,5,0,5" LineBreakMode="TailTruncation"
WidthRequest="100"/>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</listView:SfListView.GroupHeaderTemplate>
</listView:SfListView> |
public class KeyToValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var contact = (value as IEnumerable).Cast<Contacts>().First();
if (contact != null)
return contact.ContactName;
else
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
} |