Find Parent Row and Change the Height

jrahma 111 Reputation points
2020-11-20T20:17:48.723+00:00

Hi,

I have this XAML:

<Grid Margin="15">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>

    <Label Grid.Column="0" Grid.Row="0" x:Name="LabelMemberFirstName" Text="First Name :" FontAttributes="Bold" TextColor="Red" VerticalTextAlignment="Center" Margin="0,0,15,15" />
    <Label Grid.Column="1" Grid.Row="0" x:Name="LabelMemberFirstNameDetails" VerticalTextAlignment="Center" Margin="0,0,15,0" />

    <Label Grid.Column="0" Grid.Row="1" IsVisible="False" x:Name="LabelMemberSecondName" Text="Second Name :" FontAttributes="Bold" TextColor="Red" VerticalTextAlignment="Center" Margin="0,0,15,15" />
    <Label Grid.Column="1" Grid.Row="1" IsVisible="False" x:Name="LabelMemberSecondNameDetails" VerticalTextAlignment="Center" Margin="0,0,15,0" />

    <Label Grid.Column="0" Grid.Row="4" x:Name="LabelMemberLastName" Text="Last Name :" FontAttributes="Bold" TextColor="Red" VerticalTextAlignment="Center" Margin="0,0,15,15" />
    <Label Grid.Column="1" Grid.Row="4" x:Name="LabelMemberLastNameDetails" VerticalTextAlignment="Center" Margin="0,0,15,0" />
</Grid>

I am checking at the codebehind for the second name value for example:

if (!string.IsNullOrWhiteSpace(Convert.ToString(data[0].second_name)))
{
    LabelMemberSecondNameDetails.Text = Convert.ToString(data[0].second_name);

    LabelMemberSecondName.IsVisible = true;
    LabelMemberSecondNameDetails.IsVisible = true;
}
else
{
    LabelMemberSecondName.IsVisible = false;
    LabelMemberSecondNameDetails.IsVisible = false;
}

but that is leaving a space of the row which result many spaces when I have second, third and fourth name.

How can I hide the row or set it's row to zero after checking for the value and when setting the LabelMemberSecondName and LabelMemberSecondNameDetails to false?

Thanks,
Jassim

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,295 questions
{count} votes

1 answer

Sort by: Most helpful
  1. JarvanZhang 23,951 Reputation points
    2020-11-23T06:09:32.95+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    As JamesMontemagno said, try setting the RowDefinition.Height to Auto. The default value of the RowDefinition.Height property is *.

       <Grid Margin="15">  
           <Grid.ColumnDefinitions>  
               <ColumnDefinition Width="Auto" />  
               <ColumnDefinition Width="*" />  
           </Grid.ColumnDefinitions>  
           <Grid.RowDefinitions>  
               <RowDefinition Height="Auto" />  
               <RowDefinition Height="Auto" />  
               <RowDefinition Height="Auto" />  
               <RowDefinition Height="Auto" />  
           </Grid.RowDefinitions>  
         
           ...  
       </Grid>  
    

    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments