Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Xamrin.Forms iOS ListView - ViewCell height is wrong ONLY on application start after fresh install

$
0
0

I have a xaml based ListView ViewCell with an image and 3 grid rows of text that is not rendering properly the FIRST TIME the application is started.

It is the first page of the application after logging in. When it does not render properly the content inside the ItemTemplate's ViewCell is clipped because the viewcell is too small, or if I change some properties the images will spill into the next row.

  • If you navigate to a new page (popping the problem page completely off the stack) and then come back it renders properly.
  • If you close the application and startup again, it renders properly.
  • I have only noticed this on smaller iPads and iPad simulators. Not a problem on large iPad. Probably an issue on phones but not verified.

It is so strange that the only time I can reproduce is after a fresh install and initial rendering.

I have tried many sizing configurations to remedy the issue but the only thing that works is setting the ViewCell's height explicitly. This would be fine except that the first row of Text is dynamic length, and so it seems to conflict with the whole HasUnevenRows paradigm.

Based on my research I know that in the past there were some issues with dynamic cell heights in forms on iOS, and that people had come up with workarounds involving creating custom view cells for each type of ListView ItemTemplate that needed it. I would prefer to avoid that since we have many other pages that use a similar layout and they render fine (perhaps because they are not the first page of the application). Also my understanding was that HasUnevenRows = true is now working in iOS and explicitly setting ViewCell height is not necessary.

Can anyone provide guidance on why this may be happening and if perhaps we just need to update some NuGet Packages? I am approaching a delivery so I am cautious to do so, but if that will fix it I will forge ahead.

Xamarin 4.6.0.299
Xamarin.iOS 7.4.0.21
Xamarin.Forms 2.3.4.267

I have posted the ListView xaml below for reference:

                <ListView.GroupHeaderTemplate>
                    <DataTemplate>
                        <ViewCell Height="18">
                            <Label Text="{Binding Key}"
                            IsVisible="{Binding Path=BindingContext.GroupingEnabled, Source={x:Reference myPage}}"
                            TextColor="White"
                            VerticalTextAlignment="Center"
                            VerticalOptions="FillAndExpand"
                            HorizontalOptions="FillAndExpand"
                            BackgroundColor="Black"
                            FontSize="Micro"/>
                        </ViewCell>
                    </DataTemplate>
                </ListView.GroupHeaderTemplate>
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <Grid RowSpacing="0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="{StaticResource ImageGridLength}" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="50" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="25" />
                                    <RowDefinition Height="25" />
                                </Grid.RowDefinitions>
                                <Grid Grid.Row="0" Grid.Column="0" Grid.RowSpan="3">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="{StaticResource ImageGridLength}" />
                                    </Grid.RowDefinitions>
                                    <Image Source="{Binding ImageUri}"
                                           Style="{StaticResource ListViewImageStyle}"
                                           Grid.Row="0"/>
                                </Grid>

                                <Label Text="{Binding Model.Description}"
                                   FontAttributes="Bold"
                                   FontSize="Medium"
                                   Grid.Row="0"
                                   Grid.Column="1"
                                   LineBreakMode="TailTruncation"
                                   Grid.ColumnSpan="2"
                                   TextColor="Black" />
                                    <Label Text="Name" Grid.Row="1" Grid.Column="1" FontAttributes="Bold" FontSize="Small" />
                                    <Label Text="{Binding Model.Name}"  Grid.Row="1" Grid.Column="2" FontSize="Small" />
                                    <Label Text="Number" Grid.Row="2" Grid.Column="1" FontAttributes="Bold" FontSize="Small" />
                                    <Label Text="{Binding Model.Number}" Grid.Row="2" Grid.Column="2" FontSize="Small" />

                                <Grid Grid.Row="1" Grid.Column="3">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="{StaticResource ImageGridLength}" />
                                    </Grid.RowDefinitions>
                                    <Image Source="Delete.png" IsVisible="{Binding Model.CanDelete}"
                                           Grid.Row="1" Grid.Column="2" Aspect="AspectFit" VerticalOptions="Center" HorizontalOptions="Center" HeightRequest="30">
                                        <Image.GestureRecognizers>
                                            <TapGestureRecognizer
                                              Command="{Binding BindingContext.DeleteModel, Source={x:Reference myPage}}"
                                              CommandParameter="{Binding}"/>
                                        </Image.GestureRecognizers>
                                    </Image>
                                </Grid>
                            </Grid>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>

Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>