How to ViewCell.Forceupdate size call initially in Pageappearing in xamarin forms

Viewed 25

Currently am using ListviewGroupheader and item template when the user tapped I have updated the item template but in ListviewGroupheader I have two labels and an image it cannot autosize how it can be handled initially android works fine only issue in IOS xamarin.

<ListView x:Name="list" HasUnevenRows="True"  Grid.Row="3" Margin="10"  IsGroupingEnabled="True" SeparatorVisibility="None" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
            ItemsSource="{Binding List,Mode=TwoWay}"  GroupDisplayBinding="{Binding .}" local:ItemTappedAttached.Command="{Binding TemplateItemTappedCommand}">
                <ListView.GroupHeaderTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <local:CornerStackLayout CornerRadius="3" Margin="0,0,0,3" Padding="10" BackgroundColor="White" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
                                    <Grid x:Name="grid"  HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition Width="Auto" />
                                        </Grid.ColumnDefinitions>

                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto" />
                                            <RowDefinition Height="Auto" />
                                        </Grid.RowDefinitions>

                                        <Grid.GestureRecognizers>
                                            <TapGestureRecognizer NumberOfTapsRequired="1" Tapped="TapGestureRecognizer_Tapped"   />
                                        </Grid.GestureRecognizers>
                                        <Image Source="{Binding Key.ImageUrl}" Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" WidthRequest="50"  HeightRequest="50" VerticalOptions="StartAndExpand" HorizontalOptions="StartAndExpand" />
                                        <Label Text="{Binding Key.Description}" Grid.Row="0" Grid.Column="1" FontAttributes="Bold" TextColor="Black" 
                                            VerticalOptions="StartAndExpand" HorizontalOptions="StartAndExpand" FontSize="15" />
                                        <Label Text="{Binding Key.Code}" Grid.Row="1" Grid.Column="1" TextColor="Black" VerticalOptions="StartAndExpand" HorizontalOptions="StartAndExpand" FontSize="15" />
                                    </Grid>
                                </local:CornerStackLayout>
                           
                        </ViewCell>
                    </DataTemplate>
                </ListView.GroupHeaderTemplate>
1 Answers

You can use Appearing event in <ViewCell> like following code.

<ViewCell  Appearing="ViewCell_Appearing">

Then you can call viewCell.ForceUpdateSize(); when Listview appearing.


  private void ViewCell_Appearing(object sender, EventArgs e)
        {
            ViewCell viewCell= sender as ViewCell;
            viewCell.ForceUpdateSize();
        }

Related