Hi
I have been trying to implement custom ListView based on Tutorial provided by CraigDunn in his git repository.
https://github.com/xamarin/xamarin-forms-samples/tree/master/CustomRenderers/ListView
I have created new Tab with my custom Listview. I came across a problem when i tried to bind items on the listView. Everything seems fine as long as you add items to the list in a c# like this:
public WojTab()
{
InitializeComponent();
nativeListView3.Items = DataSource3.GetList();
}
async void OnItemSelected (object sender, SelectedItemChangedEventArgs e)
{
await Navigation.PushModalAsync (new DetailPage (e.SelectedItem));
}
However problems starts once you try to bind that list in an actual XAML:
<StackLayout>
<Grid HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Text="Woj's Page" HorizontalTextAlignment="Center"/>
<local:NativeListView3 Grid.Row="1" x:Name="nativeListView3" ItemSelected="OnItemSelected" VerticalOptions="FillAndExpand" Items="dataSource" />
</Grid>
</StackLayout>
dataSource is a public property of "List" which I add in a similar fashion.
dataSource = DataSource3.GetList();
public class DataSource3
{
public string Name { get; set; }
public string Category { get; set; }
public string ImageFilename { get; set; }
public DataSource3()
{
}
public DataSource3(string name, string category, string imageFilename)
{
Name = name;
Category = category;
ImageFilename = imageFilename;
}
public static List<DataSource3> GetList()
{
var l = new List<DataSource3>();
l.Add(new DataSource3("FirstItem", "FirstItem", "FirstItem"));
l.Add(new DataSource3("Item", "Item", "Item"));
l.Add(new DataSource3("Item2", "Item2", "Item2"));
l.Add(new DataSource3("Ite3", "Ite3", "Ite3"));
l.Add(new DataSource3("Ite4", "Ite4", "IteIte4m"));
l.Add(new DataSource3("Item5", "Item", "Item"));
l.Add(new DataSource3("Item6", "Item", "Item"));
l.Add(new DataSource3("Item7", "Item", "Item"));
l.Add(new DataSource3("Item8", "Item", "Item"));
l.Add(new DataSource3("Item9", "Item", "Item"));
l.Add(new DataSource3("Item10", "Item", "Item"));
l.Add(new DataSource3("Item11", "Item", "Item"));
l.Add(new DataSource3("Item12", "Item", "Item"));
l.Add(new DataSource3("Item13", "Item", "Item"));
l.Add(new DataSource3("Item14", "Item", "Item"));
l.Add(new DataSource3("Item15", "Item", "Item"));
return l;
}
}
If I do it in XAML I get an exception. Stating that compiler cannot convert System.String to List
My question is: Am I doing something wrong or you actually cannot Bind Items in ListView in XAML to certain property with Custom Renderers (bear in mind no MVVM is used here).