locked
Why does my ViewCell's label text disappear at small row heights in Xamarin Forms? RRS feed

  • Question

  • User216512 posted

    I am trying to shrink the row size of a ListView in Xamarin that has so far been pretty reliable. The items look like this right now:

    enter image description here

    However, I now want to shrink them. I adjust the row height, and I get this:

    enter image description here

    What am I doing wrong? I have the property HasUnevenRows set to true, which seems to be what most questions advise. I have also read about bugs with the ListView on UWP: https://bugzilla.xamarin.com/show_bug.cgi?id=48428. But I'm developing for Android. Am I missing something fundamental here? Because this doesn't seem as intuitive as it should.

    Here is my XAML:

                           <ListView 
                              ItemsSource="{Binding SummaryItems}"
                              VerticalOptions="StartAndExpand" 
                              HorizontalOptions="Fill"
                              RowHeight="50" 
                              BackgroundColor="LightGray" 
                              HasUnevenRows="True">
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <ViewCell >
                                        <Frame CornerRadius="2.5" Margin="0, 1" VerticalOptions="FillAndExpand">
                                            <Grid>
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="*" />
                                                </Grid.RowDefinitions>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="*" />
                                                    <ColumnDefinition Width="*" />
                                                    <ColumnDefinition Width="*" />
                                                    <ColumnDefinition Width="*" />
                                                    <ColumnDefinition Width="*" />
                                                </Grid.ColumnDefinitions>
                                                <Label Grid.Column="0" VerticalOptions="Center" HorizontalOptions="Center" Text="test"  />
                                                <Label Grid.Column="1" VerticalTextAlignment="Center" HorizontalTextAlignment="Center" Text="{Binding Item2}"  />
                                                <Label Grid.Column="2" HorizontalTextAlignment="Center" Text="{Binding Item3}"  />
                                                <Label Grid.Column="3" HorizontalTextAlignment="Center" Text="{Binding Item4}"  />
                                                <Label Grid.Column="4" HorizontalTextAlignment="Center" Text="{Binding Item5}"  />
                                            </Grid>
                                        </Frame>
                                    </ViewCell>
                                </DataTemplate>
                            </ListView.ItemTemplate>
                        </ListView>
    
    Friday, February 15, 2019 2:42 PM

Answers

  • User216512 posted

    @IvanIcin answered my question on Stackoverflow: https://stackoverflow.com/questions/54711634/why-does-my-viewcells-label-text-disappear-at-small-row-heights-in-xamarin-form

    Frames have a default padding of 20 setting it to 0 fixed my issue.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, February 15, 2019 3:15 PM

All replies

  • User216512 posted

    @IvanIcin answered my question on Stackoverflow: https://stackoverflow.com/questions/54711634/why-does-my-viewcells-label-text-disappear-at-small-row-heights-in-xamarin-form

    Frames have a default padding of 20 setting it to 0 fixed my issue.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, February 15, 2019 3:15 PM
  • User371688 posted

    Congrats, and thanks for sharing the solution.

    Monday, February 18, 2019 7:19 AM