Reputation: 1806
I have defined the following Cell type in a Xamarin.Forms project:
public MyCell() // constructor
{
var messageLabel = new Label
{
FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
FontAttributes = FontAttributes.Bold,
};
messageLabel.SetBinding(Label.TextProperty, new Binding("Message"));
var dateLabel = new Label
{
FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label))
};
dateLabel.SetBinding(Label.TextProperty, new Binding("Date"));
var view = new StackLayout
{
Children = { messageLabel, dateLabel },
Orientation = StackOrientation.Vertical,
};
View = view;
}
This is called within a ListView, like so:
public MyPage()
{
var listView = new ListView()
{
ItemsSource = GetAllitems(),
ItemTemplate = new DataTemplate(typeof(MyCell)),
};
Content = listView
}
When this renders on the screen each item is really squashed up against its neighbours. I tried adding padding to the StackLayout in the MyCell class, but doing so results in text going off the screen. I'd like to have a gap between each item.
I'm think it may be worth converting the view to use Xaml to make this more clear, so if its easier to achieve as Xaml I'd accept that as an answer!
Upvotes: 1
Views: 3196
Reputation: 7189
Set the HasUnevenRows property to true on the ListView. That way you have more control over the cell size.
Also, leave RowHeight to its default value (-1).
Upvotes: 3