Tuesday, 6 October 2015

How to create custom renderer for ListView in android Xamarin.Forms?

Step 1- add follwoing code to your xaml page


<local:CustomListView  
x:Name="List"
    ItemsSource="{Binding yourDataList}"
    SelectedItem="{Binding ItemSelected, Mode=TwoWay}"
  BackgroundColor="Transparent">
  </local:CustomListView>


 Step 2- create class in your PCL

namespace YourNameSpace
{
public class CustomListView:ListView
{

}
}

 Step 3- create class platform specific like

 [assembly: ExportRenderer (typeof (CustomListView), typeof (CustomListViewRenderer))]
namespace YourNamespace.Droid
{
public class CustomListViewRenderer: ListViewRenderer
{
public CustomListViewRenderer ()
{
}
protected override void OnElementChanged (ElementChangedEventArgs<ListView> e)
{
base.OnElementChanged (e);
var listView= Control as Android.Widget.ListView;
listView.Divider = null;
listView.DividerHeight = 0;

}
}
}

No comments:

Post a Comment