1
votes

I am developing an application using Xamarin forms. I have List view in which I have a grid within a stack layout. I want to access the grid from code behind and set the 'HeightRequest' to 0.

I could do that on the Xaml page but how do i do it on code behind c#.

  <ListView x:Name="lvPendingDockets" HasUnevenRows="True">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout x:Name="slPendingDocket" Padding="5" Orientation="Vertical" >
                             <Grid x:Name="dActions" HeightRequest="0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Button x:Name="btnReject" Text="Reject" Grid.Column="1" Style="{StaticResource SButtonGreen}"/>
                                <Button x:Name="btnInterested" Text="Interested" Grid.Column="0" Style="{StaticResource SButtonGreen}"/>                                    
                            </Grid>
              </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

From code behind. How do I set the HeightRequest for the 'dActions' grid

<Grid x:Name="dActions" HeightRequest="0"> 

Thanks for your help Rao

1

1 Answers

1
votes

You could add a property in your list, that you bind to your ListView, something like

public double GridHeight {get;set;}

Then in your ListView DataTemplate do this

<Grid x:Name="dActions" HeightRequest="{Binding GridHeight}">

Then in your VM or code behind, you just need to access the item in your list, and change its value.