I'm trying to make a simple listView with Xamarin Forms. The listView works in android, but on iOS i get a bugg where the content is missplaced over the cells. See my image and code below:
This is my code:
Page
public class TablePage
{
public static Page GetTablePage ()
{
//Get NewsItems to populate listView
var NewsItemList = DataAccessLayer.GetNewsItemList ();
ListView listView = new ListView {
ItemsSource = NewsItemList,
ItemTemplate = new DataTemplate (typeof(NewsCell))
};
return new ContentPage {
Content = new StackLayout {
Children = {
listView
}
},
Title = "Table",
};
}
}
Cell:
public class NewsCell : ViewCell
{
public NewsCell ()
{
var headerLabel = new Label();
var contentLabel = new Label();
headerLabel.SetBinding(Label.TextProperty, "header");
contentLabel.SetBinding(Label.TextProperty, "content");
var s = new StackLayout();
s.Padding = 20;
s.Children.Add(headerLabel);
s.Children.Add(contentLabel);
this.View = s;
}
}
DataAccessLayer for items:
public static List<NewsItem> GetNewsItemList()
{
List<NewsItem> NewsItemList = new List<NewsItem> ();
NewsItemList.Add(new NewsItem { header = "News1", content = "content1"});
NewsItemList.Add(new NewsItem { header = "News2", content = "content2"});
NewsItemList.Add(new NewsItem { header = "News3", content = "content3"});
NewsItemList.Add(new NewsItem { header = "News4", content = "content4"});
return NewsItemList;
}
What am i doing wrong?
Padding
on yourStackLayout
- either that or setting theRowHeight
of yourListView
to be larger to accomodate all thatPadding
– rwisch45