Issue
I'm using StackLayout and ListView to show some part of a view, but the ListView takes more space than I need, and leaves a blank space between the last row of the list and the profile continuation. It seems my ListView has more lines than the real list's length, or it has a fixed Height, I don't know... Here's my XAML:
<ScrollView>
<StackLayout Orientation="Vertical" Spacing="10">
<Label Text="{Binding Establishment.Name}" TextColor="Black" HorizontalOptions="StartAndExpand" Style="{DynamicResource TitleStyle}" FontAttributes="Bold"/>
<Label Text="{Binding Establishment.Category.Name, StringFormat='Categoria: {0}'}" TextColor="Black" HorizontalOptions="StartAndExpand" FontAttributes="Bold"/>
<Label Text="{Binding Establishment.Description}" TextColor="Black" HorizontalOptions="StartAndExpand" LineBreakMode="WordWrap" XAlign="Start"/>
<Label Text="Contatos" TextColor="Black" HorizontalOptions="StartAndExpand" FontAttributes="Bold"/>
<ListView ItemsSource="{Binding Establishment.Contacts}" VerticalOptions="Start" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding Value}" Detail="{Binding StringType}" DetailColor="Gray"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Label Text="Endereço" TextColor="Black" HorizontalOptions="StartAndExpand" FontAttributes="Bold"/>
<Label Text="{Binding Establishment.FullAddress}" TextColor="Black" HorizontalOptions="StartAndExpand" />
<Button Text="Ver no mapa"/>
</StackLayout>
</ScrollView>
How can I fix it? I saw people using HasUnevenRows="True"
but it didn't work to me.
Solution
Thank you guys, but nothing worked for me. The solution that I thought by myself surely isn't the best one, but it works for me.....
At the XAML I left an empty StackLayout like this:
<StackLayout x:Name="ContactsList" Orientation="Vertical" Spacing="10" Padding="8,0">
<!-- Empty because it will be filled in code mode -->
</StackLayout>
And then, in the .cs file, I called this method after InitializeComponent() method:
private void setUpContacts(Establishment establishment)
{
foreach(Contact contact in establishment.Contacts)
{
StackLayout row = new StackLayout
{
Orientation = StackOrientation.Vertical
};
row.Children.Add(new Label
{
TextColor = Color.Gray,
Text = string.Format("{0}:", contact.StringType)
});
row.Children.Add(new Label
{
TextColor = Color.Black,
FontAttributes = FontAttributes.Bold,
Text = contact.Value,
});
row.GestureRecognizers.Add(new TapGestureRecognizer {
Command = new Command(() => OnContactTapped(row, contact))
});
ContactsList.Children.Add(row);
}
}
I made this because the list isn't a really ListView, since I don't need scrolling functions directly in the list, it is just another part of the view. It won't cause any performance problem, I think, because it will have a small number of items (maximum 5). I'm marking this one as the correct answer to help others with this problem.
Please, if this is a solution that does not work for others, let me know and I'll find another way to do this.
Answered By - Rômulo M. Farias
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.